题解 | #樱花#
[NOIP2011]计算系数
https://ac.nowcoder.com/acm/problem/16596
#include <bits/stdc++.h>
#define ll long long
#define int ll
using namespace std;
const int N = 1010, mod = 10007;
int dp[2][N][N], k;
int a, b, n, m;
signed main()
{
cin >> a >> b >> k >> n >> m;
k -- ;
dp[0][1][0] = a, dp[0][0][1] = b;
for(int mark = 1; mark <= k; mark ++ ) {
for(int i = 0; i <= min(mark + 1, m); i ++ ) {
for(int j = 0; j <= min(mark + 1, m); j ++ ) {
if(i - 1 >= 0) dp[mark & 1][i][j] = (dp[mark & 1][i][j] + dp[(mark - 1) & 1][i - 1][j] * a % mod) % mod;
if(j - 1 >= 0) dp[mark & 1][i][j] = (dp[mark & 1][i][j] + dp[(mark - 1) & 1][i][j - 1] * b % mod) % mod;
}
}
}
printf("%lld\n", dp[k & 1][n][m] % mod);
return 0;
}