bcbgszyzh @ 2024-03-16 19:44:48
#include<bits/stdc++.h>
using namespace std;
int a[15],b[15],c[15],d[15];
int total,n;
int print(){
if(total<=2){
for(int k=1;k<=n;++k){
cout<<a[k]<<" ";
}
cout<<endl;
}
++total;
}
void dfs(int i){
if(i>n){
print();
return ;
}else{
for(int j=1;j<=n;++j){
if((!b[j])&&(!c[i+j])&&(!d[i-j+n])){
a[i]=j;
b[j]=1;
c[i+j]=1;
d[i-j+n]=1;
dfs(i+1);
b[j]=0;
c[i+j]=0;
d[i-j+n]=0;
}
}
}
}
int main(){
cin>>n;
dfs(1);
cout<<total;
return 0;
}
by qishifeng0001 @ 2024-03-16 20:00:43
稍等
by qishifeng0001 @ 2024-03-16 20:03:05
改为
by bcbgszyzh @ 2024-03-16 20:03:55