题目链接:点击这里
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 15;
int dx[] = {-1, -2, -2, -1, 1, 2, 2, 1};
int dy[] = {-2, -1, 1, 2, 2, 1, -1, -2};
bool st[N][N];
int n, m, sx, sy;
int ans = 0;
void dfs(int x, int y, int now)
{
if(now == 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, now + 1);
}
st[x][y] = false; // 恢复现场
}
int main()
{
int T;
cin >> T;
while(T--)
{
memset(st, false, sizeof st);
cin >> n >> m >>sx >> sy;
ans = 0;
dfs(sx, sy, 1);
cout << ans << endl;
}
return 0;
}