提交时间:2024-08-20 22:10:33
运行 ID: 173614
#include <iostream> #include <cmath> using namespace std; // 计算组合数 C(n, k) unsigned long long combination(int n, int k) { if (k>n-k) { k=n-k; // 因为 C(n, k) == C(n, n-k) } unsigned 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; unsigned long long result=combination(M + N - 2, M - 1); cout <<result<<endl; return 0; }