提交时间:2023-10-04 10:03:04

运行 ID: 104826

#include <iostream> #include <algorithm> #include <cstdio> #include <cmath> using namespace std; const int MAXN = 25; const int INF = 2147483647; const int MR = 10; long long f[MAXN][MAXN]; int dx[MR] = {-2, -1, 1, 2, 2, 1, -1, -2}; int dy[MR] = {1, 2, 2, 1, -1, -2, -2, -1}; int n, m; int x, y; int main() { scanf("%d %d %d %d", &n, &m, &x, &y); n++, m++, x++, y++; for (int i = 0;i <= 7;i++) { int nx = x + dx[i]; int ny = y + dy[i]; if (nx < 0 || nx > n) continue; if (ny < 0 || ny > m) continue; f[nx][ny] = -1; } f[x][y] = -1; f[0][1] = 1; for (int i = 1;i <= n;i++) { for (int j = 1;j <= m;j++) { if (f[i][j] != -1 && (f[i - 1][j] != -1 && f[i][j - 1] != -1)) f[i][j] = f[i - 1][j] + f[i][j - 1]; if (f[i - 1][j] == -1 && f[i][j - 1] != -1) f[i][j] = f[i][j - 1]; if (f[i][j - 1] == -1 && f[i - 1][j] != -1) f[i][j] = f[i - 1][j]; } } printf("%lld", f[n][m]); return 0; }