1037: [ZJOI2008] Birthday party time limit:10 Sec Memory limit:162 MB
submit:1650 solved:971
[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.
Solution: Dp[i][j][k1][k2] means I male, j female, male than female most k1, female than male maximum k2 number of programs
///1085422276#include <iostream>#include<cstdio>#include<cstring>#include<string>#include<algorithm>#include<queue>#include<cmath>#include<map>#include<bitset>#include<Set>#include<vector>using namespacestd; typedefLong Longll;#defineMem (a) memset (A,0,sizeof (a))#defineMeminf (a) memset (A,127,sizeof (a))#defineMemfy (a) memset (A,-1,sizeof (a))#defineTS printf ("111111\n")#definefor (I,A,B) for (int i=a;i<=b;i++)#defineForj (I,A,B) for (int i=a;i>=b;i--)#defineREAD (A, b) scanf ("%d%d", &a,&b)#defineG 9.8#defineMoD 12345678#defineEPS 1e-7#defineMAXN 1000000+10#defineINF 10000000000;inline ll read () {ll x=0, f=1; CharCh=GetChar (); 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;}//****************************************intdp[ $][ $][ -][ -];intMain () {mem (DP); intN=read (), M=read (), K=read ();DP [0][0][0][0]=1; For (I,0, N) for (J,0, m) for (K1,0, k) for (K2,0, K) {Dp[i+1][j][k1+1][max (k2-1,0)]+=DP[I][J][K1][K2];DP [i+1][j][k1+1][max (k2-1,0)]%=MoD; Dp[i][j+1][max (k1-1,0)][k2+1]+=DP[I][J][K1][K2];DP [i][j+1][max (k1-1,0)][k2+1]%=MoD; }ll ans=0; For (I,0, K) for (J,0, k) {ans+=dp[n][m][i][j];ans%=MoD;} cout<<ans<<Endl; return 0;}
Code
Bzoj 1037: [ZJOI2008] Birthday parties party four-dimensional DP