Time Limit:10 Sec Memory limit:162 MB
submit:2257 solved:1343 Description
Today is Hidadz children's birthday, she invited a lot of friends to attend her birthday party. Hidadz with his friends in the garden, intending to
Sit in a row and play the game. For the game to not be bored, the solution should meet the following conditions: For any successive paragraph, the number of boys and girls
The difference 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 actually
is 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 very
More, they just 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
N, m≤150,k≤20.
Dp
Four-dimensional DP f[length [number of males] [number of males at the end of the population] [the number of females at the end of the period is more than the]= programme number of girls
Originally written to move from the old state to the current state, but k1,k2 the nether is not good processing, forced to change to the current state of transition to a later state
(F[i+1][j+1][k1+1][max (k2-1,0)]+=f[i][j][k1][k2])%=mod;
(F[i+1][j][max (k1-1,0)][k2+1]+=f[i][j][k1][k2])%=mod;
1 /*by Silvern*/2#include <algorithm>3#include <iostream>4#include <cstring>5#include <cstdio>6#include <cmath>7#include <vector>8 using namespacestd;9 Const intMod=12345678;Ten intRead () { One intx=0, f=1;CharCh=GetChar (); A while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} - while(ch>='0'&& ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} - returnx*F; the } - intn,m,k; - intf[305][ the][ -][ -]; - intMain () { + inti,j; -N=read (); M=read (); k=read (); + intt=n+m; Af[0][0][0][0]=1; at for(i=0; i<=t;i++)//Total - for(j=0; j<=n;j++) {//Boys - for(intk1=0; k1<=k;k1++){ - for(intK2=0; k2<=k;k2++){ -(f[i+1][j+1][k1+1][max (k2-1,0)]+=F[I][J][K1][K2])%=MoD; -(f[i+1][j][max (k1-1,0)][k2+1]+=F[I][J][K1][K2])%=MoD; in } - } to } + intans=0; - for(intk1=0; k1<=k;k1++) the for(intK2=0; k2<=k;k2++){ *(Ans+=f[t][n][k1][k2])%=MoD; $ }Panax Notoginsengcout<<ans<<Endl; - return 0; the}
Bzoj1037 [ZJOI2008] birthday party