题目:大组合数计算。
分析:简单题、组合数学、大整数模拟。
计算组合数的方法很多,本题数据量不是很大,直接利用地推公式打表即可。
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
using namespace std;
int C[101][101][51];
int main()
{
memset( C, 0, sizeof(C) );
for ( int i = 1 ; i <= 100 ; ++ i )
C[i][0][0] = C[i][i][0] = 1;
for ( int i = 1 ; i <= 100 ; ++ i )
for ( int j = 1 ; j < i ; ++ j ) {
for ( int k = 0 ; k <= 50 ; ++ k )
C[i][j][k] = C[i-1][j-1][k]+C[i-1][j][k];
for ( int k = 0 ; k <= 50 ; ++ k )
if ( C[i][j][k] > 9 ) {
C[i][j][k+1] += C[i][j][k]/10;
C[i][j][k] %= 10;
}
}
int n,m,k;
while ( cin >> n >> m && n ) {
k = m;
if ( n < 2*m ) m = n-m;
int end = 50;
while ( end > 0 && !C[n][m][end] ) -- end;
printf("%d things taken %d at a time is ",n,k);
while ( end >= 0 ) printf("%d",C[n][m][end --]);
printf(" exactly.\n");
}
return 0;
}