21 lines
428 B
C++
21 lines
428 B
C++
#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;
|
||
} |