一点简单数学知识
1.组合数
$C_a^b=\frac{a!}{b!(a-b)!}$
$C_a^b=C_{a-1}^b+C_{a-1}^{b-1}$
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| #include<bits/stdc++.h> using namespace std; const int N = 2010, mod = 1e9 + 7; int c[N][N];
void init() { for(int i = 0; i < N; i ++) for(int j = 0;j <= i;j ++) if(!j) c[i][j] = 1; else c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod; } int main() { inti(); int n; cin >> n; while(n --) { int a, b; cin >> a >> b; cout << c[a][b] << endl; } return 0; }
|
2.快速幂