"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)