Bupt归队赛, gunfight

时间:2021-08-10 09:11:14

只需要关心是否开枪,上个人和当前这个人的位置关系,转移可以前缀和优化

为了不重复,始终认为第一个就是1,最后答案乘以n

#include<bits/stdc++.h>
using namespace std;
#define rep(i, j, k) for (int i = int(j); i <= int(k); ++ i)
#define dwn(i, j, k) for (int i = int(j); i >= int(k); -- i)
typedef long long LL;
const LL MOD = 1e9 + ;
const int N = ;
LL dp[][N][N][], pre[][N][N][], suf[][N][N][]; int main() { // 前i个人,第i个人在第j个位置,有k个活着的人,这个人的状态为t(是否开枪) LL n, k;
while (cin >> n >> k) { rep(i, , ) rep(j, , n) rep(k, , n) rep(t, , )
dp[i][j][k][t] = suf[i][j][k][t] = pre[i][j][k][t] = ; dp[][][][] = ;
pre[][][][] = suf[][][][] = ;
rep(i, , n - ) {
int cur = i & , last = cur ^ ;
rep(j, , i) rep(k, , i) rep(t, , ) {
dp[cur][j][k][t] = k >= (t == )? pre[last][j - ][k - (t == )][ - t]: ;
if (t == ) {
(dp[cur][j][k][t] += (k >= ? suf[last][j][k - ][]: ) + suf[last][j][k][]) %= MOD;
}
}
rep(k, , i) rep(t, , ) pre[cur][][k][t] = , suf[cur][i + ][k][t] = ;
rep(j, , i) rep(k, , i) rep(t, , )
(pre[cur][j][k][t] = pre[cur][j - ][k][t] + dp[cur][j][k][t]) %= MOD;
dwn(j, i, ) rep(k, , i) rep(t, , )
(suf[cur][j][k][t] = suf[cur][j + ][k][t] + dp[cur][j][k][t]) %= MOD;
}
LL ans = ;
rep(i, , n - ) {
(ans += 1LL * dp[(n - ) & ][i][k - ][] + 1LL * dp[(n - ) & ][i][k][]) %= MOD;
}
ans = ans * (LL)n % MOD;
cout << ans << endl;
}
}