why 全WA??(悬关求调)
#include<bits/stdc++.h>
using namespace std;
const int N=10;
int n,a[N][N],to[5][2*N],c=0;
bool canAttack(int x,int y){
return to[1][x]==1||to[2][y]||to[3][x-y+n]==1||to[4][x+y-1]==1;
}
void print(){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cout<<a[i][j]<<" ";
}
cout<<endl;
}
cout<<endl<<c;
}
void search(int t){
if(t>n){
print();
return;
}
for(int i=1;i<=n;i++){
if(canAttack(t,i)) continue;
a[t][i]=t;
to[1][t]=1;
to[2][i]=1;
to[3][t-i+n]=1;
to[4][t+i-1]=1;
c++;
search(t+1);
a[t][i]=0;
to[1][t]=0;
to[2][i]=0;
to[3][t-i+n]=0;
to[4][t+i-1]=0;
c--;
}
}
int main(){
cin>>n;
search(1);
return 0;
}