[Bzoj 1037] [ZJOI2008] Birthday party (DP)

Source: Internet
Author: User

Title Link: http://www.lydsy.com:808/JudgeOnline/problem.php?id=1037

The topic is too god, to kneel ....

This question completely unexpectedly DP's idea, on-line of the solution to turn over to not a few reliable, eventually finally found a reliable point of the key to understand ...

First, let's simplify the subject by giving you n 0,m 1 to arrange them so that the difference between the number of 0 and 1 in any successive sequence is less than or equal to K.

Then we use f[a][b][c][d] to indicate that there is currently a 0,b of 1, 0:1 maximum number of K, 1:0 of the maximum number of scenarios of t

DP process, each added a new number, we can either add 0, also can add 1.

Plus 0 is the premise that there are 0 of the remaining numbers, and the current 0:1 is less than K

Plus 1 is the premise that there are 0 of the remaining numbers, and the current 1:0 is less than K

Finally, we will count the answers and add up the number of all legal schemes for more than 0:1 I, 1:0 J.

This is the whole process of the problem.

#include <iostream> #include <stdio.h> #include <stdlib.h> #include <string.h> #include < algorithm> #define MAXN 155#define maxm 22#define MOD 12345678using namespace Std;int F[MAXN][MAXN][MAXM][MAXM];    F[a][b][c][d]=a a 0,b of 1, 0:1 max of K, 1:0 maximum number of T scheme number int N,m,k,ans;int main () {scanf ("%d%d%d", &n,&m,&k);    F[0][0][0][0]=1; for (int i=0;i<=n;i++) for (int j=0;j<=m;j++) for (int. k=0;k<=k;k++) for (int t=0;t& lt;=k;t++) {if (F[i][j][k][t]) {if (I<n&amp ; &k<k)//New addition of a 0 F[i+1][j][k+1][max (t-1,0)]= (F[i+1][j][k+1][max (t-1,0)]+f[i][j][k][t])%mo                        D if (j<m&&t<k)//New Add a 1 F[i][j+1][max (k-1,0)][t+1]= (F[i][j+1][max (k-1,0)][t+1]+f[i] [j] K [T])                    %mod;    }} int ans=0; for (int i=0;i<=k;i++)//enumeration 0:1 up to many I for (intj=0;j<=k;j++)//enumeration 1:0 up to a maximum of J ans= (Ans+f[n][m][i][j])%mod;    printf ("%d\n", ans); return 0;}



[Bzoj 1037] [ZJOI2008] Birthday party (DP)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.