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.

54 lines
1.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <bits/stdc++.h>
using namespace std;
const int N = 22;
int ctrl[N][N];
int cnt, n, m;
int mx, my;
//深搜
void dfs(int x, int y) {
//终点
if (x == n && y == m) {
cnt++;//统计数增加1
return;
}
//如果不能走
if (x > n || y > m || ctrl[x][y]) 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;
//深搜
dfs(0, 0);
//输出
printf("%d\n", cnt);
}