-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path44_boj_9663.cpp
executable file
·58 lines (53 loc) · 1.11 KB
/
44_boj_9663.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
#include <iostream>
#include <cstdio>
using namespace std;
int n;
int cnt = 0;
int ground[15][15] = {0,};
bool check_queen(int row, int col)
{
for (int i=0; i<n; i++)
{
if (ground[row][i] == 1)
{
return false;
}
if (ground[i][col] == 1)
{
return false;
}
if (0 <= row-i && row -i < n && 0 <= col-i && col-i < n && ground[row-i][col-i] == 1)
{
return false;
}
if (0 <= row-i && row -i < n && 0 <= col+i && col+i < n && ground[row-i][col+i] == 1)
{
return false;
}
}
return true;
}
void backtracking(int row)
{
for (int col=0; col<n; col++)
{
if (check_queen(row,col))
{
if (row == n-1)
{
cnt++;
return;
}
ground[row][col] = 1;
backtracking(row+1);
ground[row][col] = 0;
}
}
}
int main()
{
scanf("%d", &n);
backtracking(0);
printf("%d\n", cnt);
return 0;
}