-
Notifications
You must be signed in to change notification settings - Fork 0
/
1799.cpp
48 lines (45 loc) · 846 Bytes
/
1799.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <bits/stdc++.h>
#define MAXN 10
using namespace std;
int n;
int ans, tmp;
int board[MAXN][MAXN];
bool ud[MAXN*2];//↘: x-y
bool du[MAXN*2];//↗: x+y
void dfs(int x, int y, int cnt){
if(y >= n){
if(y%2) y=0;
else y=1;
x++;
}
if(x >= n){
if(cnt > tmp){
tmp = cnt;
}
return;
}
if(board[x][y]&&!ud[x-y+n]&&!du[x+y+1]){
//printf("(%d, %d)\n", x, y);
ud[x-y+n]=1;
du[x+y+1]=1;
dfs(x, y+2, cnt+1);
ud[x-y+n]=0;
du[x+y+1]=0;
}
dfs(x, y+2, cnt);
}
int main(void){
cin >> n;
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
cin >> board[i][j];
}
}
dfs(0, 0, 0);
ans += tmp;
tmp = 0;
dfs(0, 1, 0);
ans += tmp;
cout << ans << "\n";
return 0;
}