"bzoj1037" "ZJOI2008" "Birthday party" "DP"

Source: Internet
Author: User

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.

The puzzle: Random guess a DP equation, and then unexpectedly accidentally a. Really touched.

Use F[i][j][p][q] to show that boys choose I, Girls choose J, boys up to more than girls p, girls up to more than boys Q number of programs.

So

F[i+1][j][p+1][max (0,q-1)]+=f[i][j][p][q]

F[i][j+1][max (0,p-1)][q+1]+=f[i][j][p][q]

Initial state f[0][0][0][0]=1; Transfer can be.

#include <iostream> #include <cstdio> #define PP 12345678 using namespace Std;int n,m,k,f[160][160][30][30], 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 p=0;p<=k;p++) for      (int q=0;q<=k;q++)        {          (F[i+1][j][p+1][max (0,q-1)]+=f[i ][J][P][Q])%=pp;          (F[i][j+1][max (0,p-1)][q+1]+=f[i][j][p][q])%=pp;        }    for (int i=0;i<=k;i++) for      (int j=0;j<=k;j++)        (ans+=f[n][m][i][j])%=pp;    cout<<ans<<endl;   }


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"bzoj1037" "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.