标签:
组合数专题
直接贴上代码,以后再补充。。。。。。
方法1:
const int N = 1e5 + 10; const int MOD = 1e9 + 7; int f[N], finv[N], inv[N]; void init(void) { inv[1] = 1; for (int i=2; i<N; ++i) { inv[i] = (MOD - MOD / i) * 1ll * inv[MOD%i] % MOD; } f[0] = finv[0] = 1; for (int i=1; i<N; ++i) { f[i] = f[i-1] * 1ll * i % MOD; finv[i] = finv[i-1] * 1ll * inv[i] % MOD; } } int comb(int n, int k) { //C (n, k) % MOD if (k < 0 || k > n) return 0; return f[n] * 1ll * finv[n-k] % MOD * finv[k] % MOD; }
方法2:
const int N = 2000 + 10; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; int comb[N][N]; void init(void) { for (int i=0; i<N; ++i) { comb[i][i] = comb[i][0] = 1; for (int j=1; j<i; ++j) { comb[i][j] = comb[i-1][j] + comb[i-1][j-1]; if (comb[i][j] >= MOD) { comb[i][j] -= MOD; } } } //printf ("%d\n", comb[6][3]); }
标签:
原文地址:http://www.cnblogs.com/Running-Time/p/4749067.html