提交时间:2024-08-20 23:21:52

运行 ID: 173665

#include <iostream> using namespace std; long long cd(int n, int k) { if (k > n) return 0; if (k * 2 > n) k = n - k; long long result = 1; for (int i = 0; i < k; ++i) { result = result * (n - i) / (i + 1); } return result; } int main() { int M, N; cin >> M >> N; if (N>=1 && N<1040 && M>=0 && M<=1000){ if (M == 0 || N == 0) { cout << 0 << endl; } else { long long paths = cd(M + N - 2, M - 1); cout << paths << endl; } } return 0; }