-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP1219.cpp
More file actions
42 lines (38 loc) · 674 Bytes
/
P1219.cpp
File metadata and controls
42 lines (38 loc) · 674 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
#include<bits/stdc++.h>
using namespace std;
const int maxn =13+1;
int n;
int tot=0;
int show=0;
int col[maxn],ans[maxn];
bool CHECK(int r,int c){
for(int i=0;i<r;i++){
if(col[i]==c||abs(i-r)==abs(c-col[i])) return false;
}
return true;
}
void dfs(int s){
if(s==n+1){
tot++;
show++;
if(show<=3){
for(int i=1;i<=n;i++){
cout<<col[i]<<" ";
}
cout<<"\n";
}
return ;
}
for(int i=1;i<=n;i++){
if(CHECK(s,i)){
col[s]=i;
dfs(s+1);
}
}
}
int main(){
cin>>n;
dfs(1);
cout<<tot<<"\n";
return 0;
}