20分求助!!(1点RE,345WA)
查看原帖
20分求助!!(1点RE,345WA)
791121
potato_LG楼主2022/9/9 19:29
#include <iostream>
#include <vector>

using namespace std;
int main() {
    long long tx, ty, hx, hy;
    cin >> tx >> ty >> hx >> hy;

    // 变量初始化
    vector<vector<long long>> dp(tx + 1, vector<long long>(ty + 1, 0));
    for (int i = 0; i <= tx; i++) {
        if (abs(i - hx) * abs(i - hx) + hy * hy != 5)
            dp[i][0] = 1;
        else break;
    }
    for (int i = 0; i <= tx; i++) {
        if (hx * hx + abs(i - hy) * abs(i - hy) != 5)
            dp[0][i] = 1;
        else break;
    }
    dp[hx][hy] = 0;

    for (int i = 1; i <= tx; i++) {
        for (int j = 1; j <= ty; j++) {
            if (abs(i - hx) * abs(i - hx) + abs(j - hy) * abs(j - hy) != 5) {
                if (!(i == hx && j == hy))
                    // 到(i,j)点的走法个数取决于该点左侧和上侧点的走法
                    dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
            }
        }
    }
    cout << dp[tx][ty];
    return 0;
}
2022/9/9 19:29
加载中...