#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std ;
const int N = 30 ;
int g[N][N] ;
int t , m , n ,sx , sy ;
int ans ;
bool v[N][N] ;
int d[8][2] = {{-2,1},{-1,2},{1,2},{2,1},{2,-1},{1,-2},{-1,-2},{-2,-1} };
void dfs(int x ,int y , int u ){
if(u == n * m){
ans ++ ; return ;
}
for(int i = 0 ; i < 8 ; i ++){
int tx = x + d[i][0] , ty = y + d[i][1] ;
if(v[tx][ty] == 0 && tx >= 0 && tx < n && ty >= 0 && ty < m ){
v[tx][ty] = 1 ;
dfs(tx,ty,u+1) ;
v[tx][ty] = 0 ;
}
}
}
int main(){
cin >> t ;
while(t --){
cin >> n >> m >> sx >> sy ;
memset(v,0,sizeof(v)) ;
ans = 0 ;
v[sx][sy] = 1 ;
dfs(sx,sy, 1) ;
cout << ans << endl;
}
}
acwing 1116 马走日
最新推荐文章于 2024-06-23 20:37:41 发布