搜索专题整理复习
#include <cstring>
#include <iostream>
using namespace std;
int g[10][10], v[10][10];
int n, m, x, y;
int ans;
int dx[] = {-2, -1, 1, 2, 2, 1, -1, -2};
int dy[] = {1, 2, 2, 1, -1, -2, -2, -1};
void dfs(int x, int y, int cnt) {
if (cnt == m * n) {
ans++; return;
}
v[x][y] = 1;
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 (v[a][b]) continue;
dfs(a, b, cnt + 1);
}
v[x][y] = 0;
}
int main() {
int T; cin >> T;
while (T -- ) {
ans = 0;
memset(v, 0, sizeof (v));
cin >> n >> m >> x >> y;
dfs(x, y, 1);
cout << ans << endl;
}
return 0;
}