ShanLin | 2021-08-07 20:48:55
Author
#include<iostream>
using namespace std;
const int N=12,M=10000;
int x[M],y[M],ans;
int f[2][2]={0,1,1,0};
void dfs(int a[][N],int n,int step){
if(x[step]==n&&y[step]==n){
for(int i=step-1;i>0;i--){
a[x[i]][y[i]]=1;
}
ans++;
dfs(a,n,0);
}
for(int i=0;i<2;i++){
int ax=x[step]+f[i][0],ay=y[step]+f[i][1];
if(a[ax][ay]==0&&ax<=n&&ay<=n&&ax>0&&ay>0){
a[ax][ay]=1;
x[step+1]=ax,y[step+1]=ay;
dfs(a,n,step+1);
a[ax][ay]=0;
x[step+1]=0,y[step+1]=0;
}
}
return;
}
int main(){
int test;
cin>>test;
while(test--){
int n;cin>>n;
int a[N][N]={0};
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
char op; cin>>op;
if(op=='.')a[i][j]=0;
else a[i][j]=1;
}
}
ans=0; x[0]=1,y[0]=1;
dfs(a,n,0);
cout<<ans<<endl;
}
getchar();
}