http://ybt.ssoier.cn:8088/problem_show.php?pid=1219
#include<bits/stdc++.h>
using namespace std;
int a[20][20];
int v[20][20];
int go[8][2] = {{1,2},{2,1},{-1,2},{2,-1},{-1,-2},{-2,-1},{-2,1},{1,-2}};
int cns;
int n,m,x,y,T;
int dian=1; // 开始就是1
void print(){
for(int i=0;i<20;i++){
for(int j=0;j<20;j++){
cout<<v[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
cout<<endl;
}
void dfs(int x,int y){
// 如果dian已经有了这么多次,就满足全部搞掂,cns++
if(dian==n*m){
cns++;
// print();
return;
}
for(int i=0;i<8;i++){
int xx = x + go[i][0];
int yy = y + go[i][1];
if(xx>=0 && yy>=0 && xx<n && yy<m && v[xx][yy]==0){
v[xx][yy]++;
dian++;
dfs(xx,yy);
v[xx][yy] = 0;
dian--;
}
}
return;
}
int main(){
freopen("cpp.in","r",stdin);
freopen("cpp.out","w",stdout);
cin>>T;
while(T--){
cin>>n>>m>>x>>y;
memset(v,0,sizeof(v));
v[x][y] = 1; //记得要一开始就将起始点设置成 1
cns=0;
dfs(x,y);
cout<<cns<<endl;
}
return 0;
}