You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
#include<bits/stdc++.h>
|
|
|
|
|
// https://blog.csdn.net/qq_41923622/article/details/79756107
|
|
|
|
|
using namespace std;
|
|
|
|
|
int a[10][10];
|
|
|
|
|
int bj[3][20]= {0};
|
|
|
|
|
int bj1[3][20]= {0};
|
|
|
|
|
int n;
|
|
|
|
|
int sum=0;
|
|
|
|
|
void f2(int x ) {
|
|
|
|
|
int y;
|
|
|
|
|
if(x==n)sum++;
|
|
|
|
|
else {
|
|
|
|
|
for(y=0; y<n; y++)
|
|
|
|
|
if(a[x][y]==1&&bj1[0][y]==0&&bj1[1][x+y]==0&&bj1[2][x-y+n]==0) {
|
|
|
|
|
a[x][y]=3;
|
|
|
|
|
bj1[0][y]=bj1[1][x+y]=bj1[2][x-y+n]=1;
|
|
|
|
|
f2(x+1);
|
|
|
|
|
bj1[0][y]=bj1[1][x+y]=bj1[2][x-y+n]=0;
|
|
|
|
|
a[x][y]=1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void f(int x ) { //<2F><><EFBFBD>ð<C3B0>
|
|
|
|
|
int y;
|
|
|
|
|
if(x==n)f2(0);//<2F><><EFBFBD><EFBFBD> <20>ں<EFBFBD>
|
|
|
|
|
else {
|
|
|
|
|
for(y=0; y<n; y++)
|
|
|
|
|
if(a[x][y]==1&&bj[0][y]==0&&bj[1][x+y]==0&&bj[2][x-y+n]==0) { //<2F><><EFBFBD>ҶԽ<D2B6> <20><> <20>͵<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD>궼δ<EAB6BC><CEB4><EFBFBD><EFBFBD><EFBFBD>ǿɷ<C7BF>
|
|
|
|
|
a[x][y]=2;//<2F><><EFBFBD>ǰ<C7B0> <20><><EFBFBD><EFBFBD>λ<EFBFBD><CEBB> Ϊ<><CEAA><EFBFBD><EFBFBD><EFBFBD>úں<C3BA> <20><><EFBFBD><EFBFBD>
|
|
|
|
|
bj[0][y]=bj[1][x+y]=bj[2][x-y+n]=1;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҶԽ<D2B6> <20><>
|
|
|
|
|
f(x+1);
|
|
|
|
|
bj[0][y]=bj[1][x+y]=bj[2][x-y+n]=0;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
a[x][y]=1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
int main() {
|
|
|
|
|
int i,j;
|
|
|
|
|
scanf("%d",&n);
|
|
|
|
|
for(i=0; i<n; i++)
|
|
|
|
|
for(j=0; j<n; j++)
|
|
|
|
|
scanf("%d",&a[i][j]);
|
|
|
|
|
f(0);
|
|
|
|
|
printf("%ld\n",sum);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|