Files
python/TangDou/LuoGuBook/P1002_2.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

48 lines
974 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
const int N = 22;
int ctrl[N][N];
int n, m;
int mx, my;
//深搜
int dfs(int x, int y) {
//终点
if (x == n && y == m) return 1;
//不能走
if (ctrl[x][y] || x > n || y > m) return 0;
//向右 向下
return dfs(x + 1, y) + dfs(x, y + 1);
}
//增量数组delta
int d[8][2] = {
{1, 2},
{1, -2},
{-1, 2},
{-1, -2},
{2, 1},
{2, -1},
{-2, 1},
{-2, -1}};
int main() {
//读入B点坐标和马的坐标
cin >> n >> m >> mx >> my;
//马的实际控制范围
for (int i = 0; i < 8; i++) {
int tx = mx + d[i][0], ty = my + d[i][1];
if (tx >= 0 && tx <= n && ty >= 0 && ty <= m) ctrl[tx][ty] = 1;
}
//马所在的位置你也不能走,也踢你~
ctrl[mx][my] = 1;
//深搜
int sum = dfs(0, 0);
//输出
printf("%d\n", sum);
}