代码:
#include<bits/stdc++.h>
using namespace std;
int n,m,ma,mb;
bool a[111][111];
int ans = 0;
int dx[8] = {1,1,2,2,-1,-1,-2,-2};
int dy[8] = {2,-2,-1,1,-2,2,1,-1};
void dfs(int x,int y,int z){
if(z == n * m) ans++;
else{
for(int i = 0;i < 8;i++){
int xx = x + dx[i];
int yy = y + dy[i];
if(xx < n&&xx >= 0&& yy < m&&yy >= 0&&!a[xx][yy]){
a[xx][yy] = 1;
dfs(xx,yy,z+1);
a[xx][yy] = 0;
}
}
}
}
int main(){
int t;
cin >> t;
while(t--){
ans = 0;
cin >> n >> m >> ma >> mb;
a[ma][mb] = 1;
dfs(ma,mb,1);
cout << ans << endl;
for(int i = 0;i < n;i++){
for(int j = 0;j < n;j++){
a[ma][mb] = 0;
}
}
}
return 0;
}