-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcses_1624.cpp
More file actions
56 lines (50 loc) · 948 Bytes
/
cses_1624.cpp
File metadata and controls
56 lines (50 loc) · 948 Bytes
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
#include <bits/extc++.h>
using namespace std;
int cnt, r[10];
bool occupy[10][10], c[10];
bool legal(int x, int y, int step)
{
if (c[y])
return false;
if (occupy[x][y])
return false;
for (int i = 0; i < step; i++)
{
if (abs(r[i] - y) == abs(i - x))
return false;
}
return true;
}
void dfs(int step)
{
if (step == 8)
{
cnt++;
return;
}
for (int i = 0; i < 8; i++)
if (legal(step, i, step))
{
r[step] = i;
c[i] = true;
dfs(step + 1);
r[step] = 0;
c[i] = false;
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
char ch;
for (int i = 0; i < 8; i++)
for (int j = 0; j < 8; j++)
{
cin >> ch;
if (ch == '*')
occupy[i][j] = true;
}
dfs(0);
cout << cnt << '\n';
return 0;
}