ER了求教
查看原帖
ER了求教
1646968
luo37288楼主2025/7/19 09:55
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, m, cx, cy; 
int dx[] = {1, 1, -1, -1, 2, 2, -2, -2} , dy[] = {2, -2, 2, -2, 1, -1, 1, -1};
vector<vector<bool>> blocked(n + 1, vector<bool>(m + 1, false));
vector<vector<long long>> dp(n + 1, vector<long long>(m + 1, 0));
signed main() {
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> m >> cx >> cy;
    blocked[cx][cy] = true;
    for (int i = 0; i < 8; i++) {
        int nx = cx + dx[i];
        int ny = cy + dy[i];
        if (nx >= 0 && nx <= n && ny >= 0 && ny <= m) blocked[nx][ny] = true;
    }
    dp[0][0] = (blocked[0][0] ? 0 : 1);
    for (int i = 1; i <= n; i++) if(!blocked[i][0]) dp[i][0] = dp[i-1][0];
    for (int j = 1; j <= m; j++) if (!blocked[0][j]) dp[0][j] = dp[0][j-1];
    for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) if (!blocked[i][j]) dp[i][j] = dp[i-1][j] + dp[i][j-1];
    cout << dp[n][m] << endl;
    return 0;
}
2025/7/19 09:55
加载中...