1 条题解
-
1
张子瑞 LV 8 @ 2025-03-28 20:29:35
#include <iostream>
using namespace std;const int N = 10;
int n, m, x, y;
bool st[N][N];
int dx[8] = {-2, -1, 1, 2, 2, 1, -1, -2};
int dy[8] = {1, 2, 2, 1, -1, -2, -2, -1};
int ans;void dfs(int cx, int cy, int step) {
if (step == n * m) {
ans++;
return;
}for (int i = 0; i < 8; i++) {
int newX = cx + dx[i];
int newY = cy + dy[i];
if (newX >= 0 && newX < n && newY >= 0 && newY < m &&!st[newX][newY]) {
st[newX][newY] = true;
dfs(newX, newY, step + 1);
st[newX][newY] = false;
}
}
}int main() {
int T;
cin >> T;
while (T--) {
cin >> n >> m >> x >> y;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
st[i][j] = false;
}
}
ans = 0;
st[x][y] = true;
dfs(x, y, 1);
cout << ans << endl;
}
return 0;
}666
- 1
信息
- ID
- 1513
- 难度
- 10
- 分类
- (无)
- 标签
- 递交数
- 45
- 已通过
- 0
- 通过率
- 0%
- 被复制
- 4
- 上传者