Bzoj 1037 [ZJOI2008] birthday party (DP)

Source: Internet
Author: User

"Topic link"

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

Test instructions

A row of n male m female, the number of men and women to meet any number of consecutive segments of the difference does not exceed K.

Ideas

Dp

Set f[a][b][c][d] to indicate a male m female, the maximum number of male and female students is C, the maximum number of girls and boys is the program number of D, there is a transfer equation:

F[a+1][b][c+1][max (d-1,0)]<-f[a][b][c][d]

F[a][b+1][max (c-1,0)][d+1]<-f[a][b][c][d]

Too hot-<

Code

1#include <cstdio>2#include <iostream>3 #definefor (A,B,C) for (int a=b;a<=c;a++)4 using namespacestd;5 6 Const intN = $;7 Const intMOD =12345678;8 9 intf[n][n][ -][ -];Ten intn,m,k; One  A intMain () - { -scanf"%d%d%d",&n,&m,&K); thef[0][0][0][0]=1; -For (A,0, n) for (b,0, M) -for (c,0, K) for (D,0, K) -         if(F[a][b][c][d]) { +             if(a<n&& (c<K)) { -f[a+1][b][c+1][max (d1,0)]= (f[a+1][b][c+1][max (d1,0)]+f[a][b][c][d])%MOD; +             }  A             if(b<m&&d<K) { atf[a][b+1][max (C-1,0)][d+1]= (f[a][b+1][max (C-1,0)][d+1]+F[A][B][C][D])%MOD; -             } -         } -     intans=0; -for (c,0, K) for (D,0, K) -Ans= (Ans+f[n][m][c][d])%MOD; inprintf"%d\n", ans); -}

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.