PE其他解题报告请参考这里,本题答案在留言首条
Combinatoric selections
Problem 53
There are exactly ten ways of selecting three from five, 12345 12345 12345:
123 , 124 , 125 , 134 , 135 , 145 , 234 , 235 , 245 , a n d 345 123, 124, 125, 134, 135, 145, 234, 235, 245, and 345 123,124,125,134,135,145,234,235,245,and345
In combinatorics, we use the notation, 5 C 3 = 10 5C_3 = 10 5C3=10.
In general,
n
C
r
=
n
!
r
!
n
!
−
r
!
nC_r = \frac {n!r!}{n!−r!}
nCr=n!−r!n!r!,where r ≤ n, n! = n×(n−1)×…×3×2×1, and 0! = 1.
It is not until n = 23, that a value exceeds one-million: 23C10 = 1144066.
How many, not necessarily distinct, values of nCr, for 1 ≤ n ≤ 100, are greater than one-million?
题意:
让你求组合数 C n m C_n^m Cnm 1 <= n <= 100, 1 <= m <= n,大于一百万的组合数的个数
分析:
根据组合数的性质,暴力跑就行,如果大于一百万,就赋值1000001,这样保证不会爆int
参考代码
#include<bits/stdc++.h>
using namespace std;
int c[111][111];
void init() {
c[0][0] = 1;
int cnt = 0;
for (int i = 1; i <= 100; i++) {
for (int j = 0; j <= i; j++) {
if (j == 0 || j == i) c[i][j] = 1;
else {
int t = c[i - 1][j] + c[i - 1][j - 1];
if (t > 1000000) c[i][j] = (int)(1e6) + 1, cnt++;
else c[i][j] = t;
}
}
}
cout << cnt << endl;
}
int main(){
init();
return 0;
}```
***阅读好习惯:点赞 + 收藏~***