-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1799.cpp
42 lines (39 loc) · 835 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
#include<iostream>
#include<vector>
using namespace std;
int n, answer[2];
bool board[11][11], flag;
bool in[20], de[20];
void solving(int y, int x, int cnt){
if(x >= n){
y++;
if(x%2 == 0)x = 1;
else x = 0;
}
if(y >= n){
answer[flag] = max(answer[flag], cnt);
return;
}
if(board[y][x] && in[y-x+n-1] == 0 && de[y+x] == 0){
in[y-x+n-1] = de[y+x] = 1;
solving(y, x+2, cnt+1);
in[y-x+n-1] = de[y+x] = 0;
}
solving(y, x+2, cnt);
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
cin >> board[i][j];
}
}
flag = 0;
solving(0, 0, 0);
flag = 1;
solving(0, 1, 0);
cout << answer[0] + answer[1];
}