The DP (I, j, K) indicates that the first row is considered, there are J columns with 0 cannons, and a k column with 1 cannons is placed. Time complexity O (nm^2)
--------------------------------------------------------------------------
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long Long ll;const int MAXN = 109;const int MOD = 9999973;const int INV = 4999987;int n, m;int DP[MAXN][MAXN][MAXN];inline void upd (int &x, int t) {if ((x + = t) >= MOD)x-= MOD;} int main () {scanf ("%d%d", &n, &m);memset (DP, 0, sizeof DP);dp[0][m][0] = 1;for (int i = 1; I <= n; i++)For (int j = 0; J <= M; j + +)for (int k = 0; k <= m-j; k++) {int &t = dp[i][j][k];upd (t, Dp[i-1][j][k]);if (k) upd (T, (j + 1) * dp[i-1][j + 1][k-1]% MOD);upd (t, (k + 1) * dp[i-1][j][k + 1]% MOD);if (k >= 2) upd (T, LL (INV) * (j + 1) * (j + 2) * dp[i-1][j + 2][k-2]% MOD);upd (T, LL (INV) * (k + 1) * (k + 2) * dp[i-1][j][k + 2]% MOD);upd (T, LL (k) * (j + 1) * dp[i-1][j + 1][k]% MOD);}int ans = 0;for (int i = 0; I <= m; i++)For (int j = 0; J <= M-i; j + +)upd (ans, dp[n][i][j]);printf ("%d\n", ans);return 0;}
--------------------------------------------------------------------------
1801: [ahoi2009]chess Chinese chess Time limit: ten Sec Memory Limit: MB
Submit: 1172 Solved: 688
[Submit] [Status] [Discuss] Description on the N-row m-column board, a number of guns can be 0, so that no cannon can attack another cannon. I ask how many kinds of placement methods, the Chinese like chess gun in the way of walking everyone should be very clear. The input row contains two integer n,m separated by a space. Output output of all scheme numbers, due to the large value, outputs its mod 9999973Sample Input1 3
Sample Output7
HINT
In addition to the case where all 3 compartments are filled with guns, everything else is possible.
100% of the data n,m not more than 100
In 50% of the data, N,m has at least one number not exceeding 8
30% of the data, n,m are not more than 6
Source
Day2
Bzoj 1801: [Ahoi2009]chess Chinese Chess (DP)