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.

51 lines
1.1 KiB

2 years ago
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 22;
int n, m, mx, my;
LL f[N][N]; //一定要开long long 不然3 4 测试点过不了
//增量数组delta
int d[8][2] = {
{1, 2},
{1, -2},
{-1, 2},
{-1, -2},
{2, 1},
{2, -1},
{-2, 1},
{-2, -1}};
int ctrl[N][N];
//搜索
LL dfs(int x, int y) {
//计算过,直接返回
if (dp[x][y]) return dp[x][y];
//走不了
if (ctrl[x][y] || x > n || y > m) return dp[x][y] = 0;
//如果是终点
if (x == n && y == m) return dp[x][y] = 1;
//如果都不是,那么需要依赖于右和下的和
return dp[x][y] = dfs(x, y + 1) + dfs(x + 1, y);
}
int main() {
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;
//开始深搜
cout << dfs(0, 0);
return 0;
}