P2051 Chinese Chess

Source: Internet
Author: User

P2051 Chinese Chess

DP problem
At first I was thinking about the shape. and found.
VOC, how n and M are 100. Then decisive GG

Thought for a long time. It then found that the cannon only had an impact on the rows and columns he was in, and had no effect on the other rows and columns.

And the cannon in the line, we can get him out at once.

So when it comes to our decisions, only the things on the list have an impact on us.

And then because the different columns don't affect each other, then we just need to record the number of each case is OK

We consider the following state of design
\ (f[i],[j],[k]\) indicates that at the moment we are in line I, there is a cannon on the \ (j\) column, there are two cannons on the \ (k\) column.

Consider transfer

Line I no blasting
\ (f[i][j][k]+=f[i-1][j][k]\)

Line I put a gun
1. Put on a column without guns
\ (f[i][j][k]+=f[i-1][j-1][k]* (m-j-k+1) \)
2. Put it on the column of a gun
\ (f[i][j][k]+=f[i-1][j+1][k-1]* (j+1) \)

Line I put two guns
1. Put them on a column without guns.
\ (f[i][j][k]+=f[i-1][j-2][k]*c^2_{m-j-k+2}\)
2. Put it on one of the cannon's columns.
\ (f[i][j][k]+=f[i-1][j+2][k-2]*c^2_{j+2}\)
3. One on the column of one cannon, the other on the column without cannon
\ (f[i][j][k]+=f[i-1][j][k-1]*j* (m-j-k+1) \)

The principle of multiplication and the principle of addition to do it.

#include <cstdio> #include <iostream> #include <algorithm> #include <cstring>const int maxn=110 ; Long long F[maxn][maxn][maxn];long long mode (Long long Val) {return val%9999973;} Long long C (int T) {return mode (t* (T-1)/2);}    int main () {f[0][0][0]=1;    int n,m;    scanf ("%d%d", &n,&m);                for (int i=1;i<=n;i++) for (int j=0;j<=m;j++) for (int k=0;k+j<=m;k++) { F[i][j][k]=mode (F[i][j][k]+f[i-1][j][k]);//Pay attention to determine the boundary if (j-1>=0) F[i][j][k]=mode (F[i][j][k]+f[i-1][j-1][k]                * (m-j+1-k));                if (j-2>=0) F[i][j][k]=mode (F[i][j][k]+f[i-1][j-2][k]*c (m-j+2-k));                if (k-1>=0) F[i][j][k]=mode (f[i][j][k]+f[i-1][j][k-1]*j* (m-j-k+1));                if (k-1>=0&&j+1<=m) F[i][j][k]=mode (f[i][j][k]+f[i-1][j+1][k-1]* (j+1));            if (k-2>=0&&j+2<=m) F[i][j][k]=mode (F[i][j][k]+f[i-1][j+2][k-2]*c (j+2));    } Long long ans=0; for (int i=0;i<=m;i++) for (int j=0;i+j<=m;j++) Ans=mode (Ans+f[n][i][j]); printf ("%lld", ans);}

P2051 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.