NOIP2011 Day2 T1(二项式定理)

$a=b=1$的时候就是裸的二项式定理,杨辉三角输出第$k$行即可
不等的时候也可以推一下,发现答案就是$C(k, m) \times a^n \times b^m$

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
26
27
28
29
30
31
32
33
34
35
36
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#define ms(i, j) memset(i, j, sizeof i)
#define LL long long
#define db double
using namespace std;
const int MAXK = 1000 + 5, MO = 10007;
int c[MAXK][MAXK];
int a, b, k, n, m;
void clean() {}
void solve() {
clean();
a %= MO, b %= MO;
for (int i = 0; i <= k; i++) c[i][0] = 1, c[i][i] = 1;
for (int i = 1; i <= k; i++) {
for (int j = 1; j < i; j++) {
c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % MO;
}
}
int ans = 1;
for (int i = 1; i <= m; i++) {
ans = (ans * a) % MO;
}
for (int i = 1; i <= n; i++) {
ans = (ans * b) % MO;
}
ans = (ans * c[k][m]) % MO;
printf("%d\n", ans);
}
int main() {
scanf("%d%d%d%d%d", &b, &a, &k, &n, &m), solve();
return 0;
}

------ 本文结束 ------