1037: [ZJOI2008] Birthday party time limit: ten Sec Memory Limit: 162 MB
Submit: 1828 Solved: 1081
[Submit] [Status] [Discuss] Description
Today is Hidadz children's birthday, she invited a lot of friends to attend her birthday party. Hidadz with his friends to the garden, planning to sit in a row to play games. For the game to not be bored, the table should meet the following conditions: For any successive paragraph, the number of boys and girls does not exceed K. Soon, the children found a way to sit down and start the game. Hidadz's good friend Susie found that such a seating plan is actually a lot of, so we quickly found a kind, then how many kinds of it? Hidadz and her friends began to think about the problem ... If there are N boys and M girls in the party, can you answer the questions of Susie and Hidadz? As this number may be many, they only want to know the remainder of this number divided by 12345678.
Input
Contains only a total of 3 integers, the number of boys N, the number of girls m, and the constant K.
Output
Should contain one row for the answer asked in the question.
Sample Input1 2 1Sample Output1HINT
For 100% of data, N, m≤150,k≤20.
Source
DP Good question ... After seeing the puzzle, the whole person is collapsed ... DP really can do anything!
With F[i][j][x][y] to the first person, a total of J boys, at the end of I at any length of boys up to more than girls X, girls up to more than the number of boys y scheme.
The state transitions are as follows:
If X+1<k,f[i+1,j+1,x+1,max (y-1,0)]+=f[i][j][x][y]
If Y+1<k,f[i+1,j,max (x-1,0), Y+1]+=f[i][j][x][y]
The final answer is ∑ (0≤i≤k) ∑ (0≤j≤k) f[n+m][n][i][j].
#include <iostream> #include <cstdlib> #include <cmath> #include <cstring> #include <cstdio > #include <algorithm> #define F (I,j,n) for (int. i=j;i<=n;i++) #define D (i,j,n) for (int i=j;i>=n;i--) # Define ll long long#define mod 12345678using namespace std;int n,m,k,ans,f[301][151][21][21];inline int read () {int x=0,f= 1;char Ch=getchar (); while (ch< ' 0 ' | | Ch> ' 9 ') {if (ch== '-') F=-1;ch=getchar ();} while (ch>= ' 0 ' &&ch<= ' 9 ') {x=x*10+ch-' 0 '; Ch=getchar ();} return x*f;} int main () {n=read (); M=read (); K=read (); f[0][0][0][0]=1; F (i,0,n+m-1) F (j,0,n) F (x,0,k) f (y,0,k) if (F[i][j][x][y]) {if (x+1<=k&&j+1<=n) (F[i+1][j+1][x+1][max ( y-1,0)]+=f[i][j][x][y])%=mod;if (y+1<=k&&i+1-j<=m) (F[i+1][j][max (x-1,0)][y+1]+=f[i][j][x][y])%= MoD;} F (i,0,k) F (j,0,k) (Ans+=f[n+m][n][i][j])%=mod;printf ("%d\n", ans);
bzoj1037 "ZJOI2008" Birthday party