Reduce the problem to a design 01 matrix each row of up to 2 1. There are several scenarios.
Set F[i][j][k] to the line I have J column put 1 chess k column put 0 chess there are two chess columns do not consider because can not be released.
The recursive equation is as follows:
F[i][j][k]=f[i-1][j][k] line I do not put.
f[i][j][k]+=f[i-1][j-1][k+1]* (k+1) put one of the columns in the I-1 row (the number of pieces of the column = 0). There are k+1 seed-putting methods.
f[i][j][k]+=f[i-1][j+1][k]* (j+1) Select a column (the number of pieces of the column = 1)
f[i][j][k]+=f[i-1][j][k+1]*j* (k+1) Select two columns one column number of pieces = 11 rows of chess pieces = 0
f[i][j][k]+=f[i-1][j-2][k+2]* (k+2) * (k+1)/2 selected two rows of chess pieces = 0
f[i][j][k]+=f[i-1][j+2][k]* (j+2) * (j+1)/2 selected two rows of chess pieces = 1
Last statistics F[n][i][j] 0<=i,j<=m;
The code is as follows:
1#include <cstdio>2#include <iostream>3 #defineMOD 99999734 #defineMAXN 1055 #definefor (i,x,y) for (int i=x;i<=y;++i)6 using namespacestd;7 Long LongF[MAXN][MAXN][MAXN];8 intMain ()9 {Ten intN,m;cin>>n>>m; Onef[1][0][m]=1; Af[1][1][m-1]=m; -f[1][2][m-2]=m* (M-1)/2; -for (I,2, N) the { -For (J,0, M) - { -For (K,0, M) + { -F[i][j][k]= (f[i-1][j][k]+f[i-1][j-1][k+1]* (k +1)%mod+f[i-1][j+1][k]* (j+1)%mod)%mod+f[i-1][j][k+1]*j* (k +1)%MOD; +f[i][j][k]+= (f[i-1][j-2][k+2]* (k +2) * (k +1)/2)%mod+f[i-1][j+2][k]* (j+2) * (j+1)/2; Af[i][j][k]%=MOD; at } - } - } - Long Longans=0; -for (I,0, M) - { inFor (J,0, M) - { toans+=F[n][i][j]; +ans%=MOD; - } the } *printf"%lld", ans); $}
Bzoj 1801 Chinese Chess DP