CF1628D1 - Game on Sum (Easy Version)(博弈DP)
正着想不好想(因为有“后效性”且无“前效性”,即之前做的决定并不影响这一状态之后的结果),不妨倒推一波。设dp[i][j]为还剩i轮且Bob还需要使用j次Add的最大值。详细题解可以参考https://www.luogu.com.cn/problem/solution/CF1628D1
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define mod 1000000007
#define N 100005
using namespace std;
int n, m, k;
ll _inv[N];
void pre(int MOD){
_inv[0]=_inv[1]=1;
for(int i=2;i<N;i++)
_inv[i]=((MOD-MOD/i)*_inv[MOD%i])%MOD;
}
int dp[2005][2005];
signed main() {
int T;
cin >> T;
pre(mod);
memset(dp, 0, sizeof(dp));
for(int i = 1; i <= 2000; i++) {
dp[i][i] = i;
dp[i][0] = 0;
}
for(int i = 2; i <= 2000; i++) {
for(int j = 1; j < i; j++) {
dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j]) % mod * _inv[2] % mod;
}
}
while(T--) {
cin >> n >> m >> k;
cout << dp[n][m] * k % mod << endl;
}
return 0;
}