Bzoj 1801 Chinese Chess DP

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.