bzoj1801: [Ahoi2009]chess Chinese chess

The problem
solution of a boss The
following content is adapted from the solution of the boss

answer:

dp[i][j][k] means that there are already 2 j columns in the first i row, and there are already 1 k columns, so the number of 0s is
mjk : ​​directly add dp[i- 1][j][k]
put one: 1. Change a column of 0 to 1; 2. Change a column of 1 to 2 and
put two: 1. Change two columns of 0 to 1; 2. Change two columns of 1 to 2; 3. Change a column of 0 to 1 and then change another column of 1 to 2
About the number of combinations:
put one: directly multiply the number of numbers to be changed (0 or 1)
Put two: the first two directly C (n , 2) (n is an optional number)
According to the multiplication principle, the last one is first multiplied by the original number of 0s, and then multiplied by the original number of 1s

Standard range:

#include<bits/stdc++.h>
using namespace std;
const int M=9999973;
long long t,f[103][103][103];
int i,j,k,n,m;
int main(){
    cin>>n>>m;
    f[0][0][0]=1;
    for (i=1;i<=n;i++)
        for (j=0;j<=m;j++)
            for (k=0;k<=m-j;k++){
                t=f[i-1][j][k];//不放
                if (j) t+=f[i-1][j-1][k+1]*(k+1);//放1个,1变2
                if (k) t+=f[i-1][j][k-1]*(m-j-k+1);//放1个,0变1
                if (j && k) t+=f[i-1][j-1][k]*k*(m-j-k+1);//放两个,0变1,1变2
                if (j>1) t+=f[i-1][j-2][k+2]*(k+2)*(k+1)/2;//放两个,两列1变2
                if (k>1) t+=f[i-1][j][k-2]*(m-j-k+2)*(m-j-k+1)/2;//放两个,两列0变1
                f[i][j][k]=t%M;
            }
    t=0;
    for (i=0;i<=m;i++)
        for (j=0;j<=m-i;j++) t=(t+f[n][i][j])%M;
    cout<<t;
}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326771091&siteId=291194637