1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
#include<bits/stdc++.h> using namespace std;
const int N=15;
int n, m, sx, sy; bool st[N][N]; int ans;
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 cnt){
if(cnt==n*m){ ans++; return ; }
st[x][y]=true;
for(int i=0;i<8;i++){ int a=x+dx[i], b=y+dy[i];
if(a<0 || a>=n || b<0 || b>=m) continue; if(st[a][b]) continue;
dfs(a, b, cnt+1); }
st[x][y]=false; }
void work(){ int T; cin>>T;
while(T--){ cin>>n>>m>>sx>>sy;
memset(st, 0, sizeof st); dfs(sx, sy, 1);
cout<<ans<<endl;
ans=0; } }
int main(){ work(); return 0; }
|