P1002 [NOIP2002 普及组] 过河卒

// Problem: P1002 [NOIP2002 普及组] 过河卒
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P1002
// Memory Limit: 125 MB
// Time Limit: 1000 ms
// User: Pannnn

#include <bits/stdc++.h>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    ++x, ++y;
    vector<vector<long long>> info(n + 2, vector<long long>(m + 2));
    vector<vector<long long>> coef(n + 2, vector<long long>(m + 2, 1));
    int dx[9] = {0, 2, 1, -1, -2, -2, -1, 1, 2};
    int dy[9] = {0, 1, 2, 2, 1, -1, -2, -2, -1};
    
    for (int i = 0; i < 9; ++i) {
        int tx = x + dx[i];
        int ty = y + dy[i];
        if (tx >= 1 && tx <= n + 1 && ty >= 1 && ty <= m + 1) {
            coef[tx][ty] = 0;
        }
    }
    
    info[0][1] = 1;
    for (int i = 1; i <= n + 1; ++i) {
        for (int j = 1; j <= m + 1; ++j) {
            info[i][j] = (info[i - 1][j] + info[i][j - 1]) * coef[i][j];
        }
    }
    cout << info[n + 1][m + 1] << endl;
    return 0;
}
posted @ 2022-02-12 17:09  Pannnn  阅读(54)  评论(0)    收藏  举报
-->