# 洛谷 [P2051] 中国象棋

## DP

orz__stdcall

30分的做法就是裸的枚举，暴搜，枚举这一行放哪里，放几个

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int MOD = 9999973;
long long  n, m, dp[105][105][105];
long long C(long long num) {
return num * (num - 1) / 2;
}
int main() {
cin >> n >> m;
dp[0][0][0] = 1;
for(int i = 1; i <= n; i++) {
for(int j = 0; j <= m; j++) {
for(int k = 0; k + j <= m; k++) {
dp[i][j][k] += dp[i - 1][j][k] % MOD;
if(j > 0) (dp[i][j][k] += dp[i - 1][j - 1][k] * (m - j - k + 1)) %= MOD;
if(j < m && k > 0) (dp[i][j][k] += dp[i - 1][j + 1][k - 1] * (j + 1)) %= MOD;
if(j > 1) (dp[i][j][k] += dp[i - 1][j - 2][k] * C(m - j - k  + 2)) %= MOD;
if(k > 0) (dp[i][j][k] += dp[i - 1][j][k - 1] * (m - j - k + 1) * j) %= MOD;
if(j < m - 1 && k > 1) (dp[i][j][k] += dp[i - 1][j + 2][k - 2] * C(j + 2)) %= MOD;
}
}
}
long long ans = 0ll;
for(int i = 0; i <= m; i++) {
for(int j = 0; j + i <= m; j++) {
(ans += dp[n][i][j]) %= MOD;
}
}
cout << ans << endl;
return 0;
}

posted @ 2018-05-22 19:35  Mr_Wolfram  阅读(123)  评论(0编辑  收藏