Bzoj 4806 Gun (dp)

Topic description

As we all know, the stacking of double cannons will be a very powerful nirvana in Chinese chess. When a cannon catches a piece, it must jump to catch a chess piece, which is commonly known as "cannon hitting a piece". 
Cannon and cannon obviously can't fight together, so rly borrowed many, many cannons and placed them on the chessboard... He wanted to know, in the N×M rectangle
There are several options for placing a number of cannons in the square (you may not place them) so that they do not catch each other.
The pieces are all the same.

Input and output format

Input format:
One line, two positive integers N and M.
N<=100,M<=100
Output format:

One line, the output scheme number mod 999983.

Input and output example

Input example #1: 
1 3
Sample output #1: 
7 

Analysis:

Obviously, only 2 or less chess pieces can be placed in a row and a column, otherwise they will attack each other;
obvious DP;
define f[i][j][k] , which means that the first i row is placed in the j column, and 1 is placed. Column k put two;

transfer equation:

f[i][j][k] += f[i-1[j][k] nothing;
f[i][j][k] += f[i-1][j-1][k] * (m - (j - 1) - k) put a pawn in the column where no pawn was placed;
f[i][j][k] += f[ i-1][j+1][k-1] * (j + 1) put one in a column with one pawn, it becomes two;
f[i][j][k] += f[ i-1][j-2][k] * C(m - (j - 2) - k, 2) put two pieces in the two columns where no pieces were put;
f[i][j][k] += f[i-1][j][k-1] * j * (m - (j - 1) - k) Place two pieces directly in a column where no pieces are placed;
f[i][j] [k] += f[i-1][j+2][k-2] * C(j + 2, 2) Do not put one in the two columns where a pawn is placed;

remember to take the modulo; the

code follows superior
// By zZhBr
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int p = 999983;
#define int long long

int n, m;

int f[105][105][105];

int years;

signed main()
{
    cin >> n >> m;
    
    f[0][0][0] = 1;
    
    for(register int i = 1 ; i <= n ; i ++)
    {
        for(register int j = 0 ; j <= m ; j ++)
        {
            for(register int k = 0 ; k <= m - j ; k ++)
            {
                
                f[i][j][k] = (f[i][j][k] + f[i-1][j][k]) % p;
                
                if(j - 1 >= 0)
                    f[i][j][k] = (f[i][j][k] + f[i-1][j-1][k] * (m - (j - 1) - k)) % p;
                
                if(k - 1 >= 0)
                    f[i][j][k] = (f[i][j][k] + f[i-1][j+1][k-1] * (j + 1))% p;
                
                if(j - 2 >= 0)    
                {    
                    int t = m - (j - 2) - k;
                    f[i][j][k] = (f[i][j][k] + f[i-1][j-2][k] * (t * (t - 1)) / 2) % p;
                }
                
                if(k - 2 >= 0)
                    f[i][j][k] = (f[i][j][k] + f[i-1][j+2][k-2] * (j + 1) * (j + 2) / 2) % p;
                
                if(k - 1 >= 0)
                    f[i][j][k] = (f[i][j][k] + f[i-1][j][k-1] * j * (m - (j - 1) - k)) % p;
                
                if(i == n) ans = (ans + f[i][j][k]) % p;
                
                //printf("n == %lld,  f[i][j][k] == %lld\n", i, f[i][j][k]);
            }
        }
    }
    
    cout << ans << endl;
    
    return 0;
}
zZhBr

 




Submission address : https://www.lydsy.com/JudgeOnline/problem.php?id=4806 ;





Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324873321&siteId=291194637