题解:
我们设dp[a][b][c][d]表示目前已经有a个男生,b个女生,在某一时刻男生最多比女生多c个,在某一时刻女生最多比男生多d个.
所以就可以转移了:
(dp[a+1][b][c+1][max(d-1,0)]+=dp[a][b][c][d])%=mod;
(dp[a][b+1][max(c-1,0)][d+1]+=dp[a][b][c][d])%=mod;
1 #include<iostream> 2 #include<cstdlib> 3 #include<cstdio> 4 #include<cmath> 5 #include<algorithm> 6 #include<cstring> 7 #include<queue> 8 #include<vector> 9 #include<set> 10 #define MAXN 500010 11 #define RG register 12 #define LL long long int 13 using namespace std; 14 const int INF=1e9; 15 const int mod=12345678; 16 int n,m,k; 17 LL dp[155][155][25][25]; 18 LL ans; 19 int main() 20 { 21 freopen("1.in","r",stdin); 22 scanf("%d%d%d",&n,&m,&k); 23 dp[0][0][0][0]=1; 24 for(int a=0;a<=n;a++) 25 for(int b=0;b<=m;b++) 26 for(int c=0;c<=k;c++) 27 for(int d=0;d<=k;d++) 28 { 29 (dp[a+1][b][c+1][max(d-1,0)]+=dp[a][b][c][d])%=mod; 30 (dp[a][b+1][max(c-1,0)][d+1]+=dp[a][b][c][d])%=mod; 31 } 32 for(int c=0;c<=k;c++) 33 for(int d=0;d<=k;d++) 34 (ans+=dp[n][m][c][d])%=mod; 35 printf("%lld\n",ans); 36 return 0; 37 }