You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
const int N = 10;
|
|
|
|
|
|
|
|
|
|
int n, m;
|
|
|
|
|
bool st[N][N]; // 是否走过
|
|
|
|
|
int ans;
|
|
|
|
|
|
|
|
|
|
// 八个方向
|
|
|
|
|
int dx[] = {-2, -1, 1, 2, 2, 1, -1, -2};
|
|
|
|
|
int dy[] = {1, 2, 2, 1, -1, -2, -2, -1};
|
|
|
|
|
|
|
|
|
|
// cnt:已经走了多少个格子
|
|
|
|
|
void dfs(int x, int y, int cnt) {
|
|
|
|
|
// 收集答案
|
|
|
|
|
if (cnt == n * m) {
|
|
|
|
|
ans++;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 8; i++) {
|
|
|
|
|
int tx = x + dx[i], ty = y + dy[i];
|
|
|
|
|
if (tx < 0 || tx >= n || ty < 0 || ty >= m) continue;
|
|
|
|
|
if (st[tx][ty]) continue;
|
|
|
|
|
|
|
|
|
|
// 标识当前格子已使用
|
|
|
|
|
st[tx][ty] = 1;
|
|
|
|
|
dfs(tx, ty, cnt + 1);
|
|
|
|
|
// 标识当前格子未使用
|
|
|
|
|
st[tx][ty] = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
int T;
|
|
|
|
|
cin >> T;
|
|
|
|
|
while (T--) {
|
|
|
|
|
int x, y;
|
|
|
|
|
cin >> n >> m >> x >> y;
|
|
|
|
|
|
|
|
|
|
// 清空状态数组
|
|
|
|
|
memset(st, 0, sizeof st);
|
|
|
|
|
// 清空方案数
|
|
|
|
|
ans = 0;
|
|
|
|
|
// 标识起点已访问
|
|
|
|
|
st[x][y] = 1;
|
|
|
|
|
// 从(x,y)出发,目前的访问个数为1
|
|
|
|
|
dfs(x, y, 1);
|
|
|
|
|
// 最终有多少条路径
|
|
|
|
|
cout << ans << endl;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|