bzoj1801: [ahoi2009]chess Chinese chess

Source: Internet
Author: User

Dp.

If the pressure DP, you can only get 50 points. and positive solution is both better than the shape of the pressure to write, but also the positive solution.

F[I][J][K] Indicates that there is a J column in line I has a chess piece, there are two pieces of k column, and then the DP transfer is good (the equation is too difficult to write, do not write ...) )

100*100*mod may explode int, so a long long is used.

#include <cstdio>#include<algorithm>#include<cstring>using namespaceStd;typedefLong LongLL;Const intMAXN = -+Ten;ConstLL mod =9999973; LL F[MAXN][MAXN][MAXN]; LL N,m,res;intMain () {scanf ("%lld%lld",&n,&m); Memset (F,0,sizeof(f)); f[0][0][0]=1;  for(LL i=1; i<=n;i++) {         for(LL j=0; j<=m;j++)         for(LL k=0; k<=m;k++)if(j+k<=m) {LL&h =F[i][j][k]; H= (h+f[i-1][J][K])%MoD; if(j>=1) h= (h+f[i-1][j-1][k]* (m-j-k+1))%MoD; if(k>=1) h= (h+f[i-1][j+1][k-1]* (j+1))%MoD; if(j>=2) h= (h+f[i-1][j-2][k]* ((m-j-k+1) * (m-j-k+2)/2))%MoD; if(k>=1) h= (h+f[i-1][j][k-1]* (m-j-k+1) *j)%MoD; if(k>=2) h= (h+f[i-1][j+2][k-2]* ((j+2) * (j+1)/2))%MoD; }} Res=0;  for(intI=0; i<=m;i++)      for(intj=0; j<=m;j++)if(i+j<=m) res= (Res+f[n][i][j])%MoD; printf ("%lld\n", RES); return 0;}

bzoj1801: [ahoi2009]chess Chinese chess

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.