题意:求Cnm
分析:组合数公式。C(n,m)=C(n-1,m-1)+C(n-1,m)
代码:
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; const int maxn = 110; double c[maxn][maxn]; int main() { int n, m; while(scanf("%d%d", &n, &m) != EOF&&(m||n)) { for(int i = 0; i < 101; i++) { c[i][0] = 1; c[i][i] = 1; } for(int i = 2; i < 101; i++) for(int j = 1; j < i; j++) c[i][j] = c[i-1][j] + c[i-1][j-1]; printf("%d things taken %d at a time is %.0f exactly. ", n, m, c[n][m]); } return 0; }