XuOuXiao1024 @ 2024-09-16 11:57:20
#include<bits/stdc++.h>
using namespace std;
int n,already,ll[15],ans,total;
bool l[15],zd[30],yd[30];
void dfs(){
if(already>=n){
if(total>=3) return;
for(int i=1;i<=n;i++){
cout<<ll[i]<<" ";
}
cout<<"\n";
ans++;
already--;
l[ll[already]]=false;
zd[already+1-ll[already]+n]=false;
yd[already+ll[already]]=false;
ll[already]=0;
total++;
return;
}
for(int i=1;i<=n;i++){
if(!(l[i]||zd[already+1+i]||yd[already-i+n])){
l[i]=true;
zd[already+1+i]=true;
yd[already-i+n]=true;
ll[++already]=i;
dfs();
l[i]=false;
zd[already+1-i+n]=false;
yd[already+i]=false;
already--;
}
}
}
int main(){
cin>>n;
dfs();
cout<<ans<<"\n";
}
by William_Z @ 2024-09-22 16:21:44
哇,giegie好膩害呀~人家好崇拜呀~giegie寫的代碼最整潔了~辣麼長~肯定都是giegie的智慧結晶~人家好喜歡呀~