-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDSA02016.cpp
More file actions
50 lines (46 loc) · 800 Bytes
/
DSA02016.cpp
File metadata and controls
50 lines (46 loc) · 800 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
#include <bits/stdc++.h>
using namespace std;
int n, cnt = 0;
int x[100], d1[100], d2[100], cot[100];
void ktao()
{
memset(cot, 0, 100);
memset(x,0,100);
memset(d1,0,100);
memset(d2,0,100);
}
void Try(int i)
{
for(int j = 1; j<=n; j++)
{
if( !d1[i-j+n] && !d2[i+j-1] && !cot[j])
{
x[i] = j;
d1[i-j+n] = 1;
d2[i+j-1] = 1;
cot[j] = 1;
if(i == n)
{
cnt++;
}
else
Try(i+1);
d1[i-j+n] = 0;
d2[i+j-1] = 0;
cot[j] = 0;
}
}
}
int main()
{
int t;
cin >> t;
while(t--)
{
cnt = 0;
ktao();
cin >> n;
Try(1);
cout << cnt << endl;
}
}