题解 | #[NOIP2002 普及组] 过河卒#
[NOIP2002 普及组] 过河卒
https://www.nowcoder.com/practice/cc1a9bc523a24716a117b438a1dc5706
#include <iostream> #include <vector> using namespace std; void DP13() { int n, m, x, y; while (cin >> n >> m >> x >> y) { vector<long long> row(m + 5, 0);//注意这个一定要给long long类型 vector<vector<long long>> dps(n + 5, row);//dps表示给定坐标点的路径数 //初始化边界条件 for (int i = 1; i < m + 1; i++) { if (i == y && x == 0) { dps[0][i] = 0; break; } if (abs(x) + abs(i - y) == 3 && x != 0 && y != i) { dps[0][i] = 0; break; } dps[0][i] = 1; } for (int i = 1; i < n + 1; i++) { if (i == x && y == 0) { dps[i][0] = 0; break; } if (abs(y) + abs(i - x) == 3 && x != i && y != 0) { dps[i][0] = 0; break; } dps[i][0] = 1; } //迭代 for (int i = 1; i < m + 1; i++) { for (int j = 1; j < n + 1; j++) { if (i == y && j == x) { dps[j][i] = 0; continue; } if (abs(i - y) + abs(j - x) == 3 && i != y && j != x) { dps[j][i] = 0; continue; } dps[j][i] = dps[j - 1][i] + dps[j][i - 1]; } } //输出 cout << dps[n][m] << endl; } } int main() { DP13(); } // 64 位输出请用 printf("%lld")