-
Notifications
You must be signed in to change notification settings - Fork 0
/
BOJ_1790번.cpp
78 lines (56 loc) · 931 Bytes
/
BOJ_1790번.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//비숍 1790번
#include<iostream>
#include<algorithm>
using namespace std;
#define MAX_SIZE 10
int map[MAX_SIZE][MAX_SIZE];
int visit[MAX_SIZE][MAX_SIZE];
int n, MAX;
bool check(int x, int y) {
while (0 <= x && 0 <= y) {
if (visit[x][y] == 1) return false;
x--;
y--;
}
return true;
}
void dfs(int d, int cnt) {
if (d == 2 * n - 1) return;
int x, y;
bool flag;
if (d < n - 1) {
x = d;
y = 0;
}
else {
x = n - 1;
y = d - n + 1;
}
flag = false;
while (0 <= x && y < n) {
if (map[x][y] == 1 && check(x, y)) {
flag = true;
visit[x][y] = 1;
MAX = max(MAX, cnt + 1);
dfs(d + 1, cnt + 1);
visit[x][y] = 0;
}
x--;
y++;
}
if (!flag) dfs(d + 1, cnt);
}
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> map[i][j];
}
}
MAX = 0;
dfs(0, 0);
cout << MAX;
return 0;
}