Files
python/TangDou/LuoGuBook/20_1_9_2.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

21 lines
428 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
//求组合数的优化后办法
//优点从1开始除和乘可以防止过早溢出和除法除不尽
LL C(int n, int m) {
LL sum = 1;
for (int i = 1; i <= m; i++)
sum = sum * (n - m + i) / i;
return sum;
}
int main() {
int n = 10, m = 4;
//组合公式法
cout << C(n, m) << endl;
return 0;
}