-
Notifications
You must be signed in to change notification settings - Fork 0
/
P1219.cpp
56 lines (56 loc) · 961 Bytes
/
P1219.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
#include <bits/stdc++.h>
using namespace std;
int n, sum;
struct solve
{
int i, j;
};
struct solve s[100];
void show()
{
for (int i = 1; i <= n; i++)
{
cout << s[i].i << ' ';
}
cout << endl;
}
void dfs(int x)
{
if (x > n)
{
if (sum < 3)
show();
sum++;
return;
}
for (int i = 1; i <= n; i++)
{
bool flag = true;
for (int j = 1; j < x; j++)
{
if (i == s[j].i || i - x == s[j].i - s[j].j || i + x == s[j].i + s[j].j)
{
flag = false;
break;
}
if (j == x - 1 && s[j].i - 1 <= i && s[j].i + 1 >= i)
{
flag = false;
break;
}
}
if (flag)
{
s[x].i = i;
s[x].j = x;
dfs(x + 1);
}
}
}
int main()
{
cin >> n;
dfs(1);
cout << sum;
return 0;
}