You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
428 B

2 years ago
#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;
}