题意
计算组合数 (nm)
题解
没有取模又需要求精确解,阶乘计算不得,逆元求不得。
根据二项式系数公式:
(nm)=(n−1m)+(n−1m−1)
直接递推求解。
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
const int maxn = 100 + 10;
struct Solution{
ll c[maxn][maxn];
int n, m;
void read(int _n, int _m){ n = _n, m = _m; }
Solution():n(0), m(0){ dp(); }
void dp(){
for(int i = 0; i < maxn; ++i) c[i][0] = 1;
for(int i = 1; i < maxn; ++i){
for(int j = 1; j < maxn; ++j)
c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
}
}
void solve(){
printf("%d things taken %d at a time is %I64d exactly.\n", n, m, c[n][m]);
}
};
int main()
{
int n, m;
Solution s;
while(cin >> n >> m && (n || m)){
s.read(n, m);
s.solve();
}
return 0;
}