http://www.lydsy.com/JudgeOnline/problem.php?id=1037
题意:
思路:
四维数组进行dp,dp[i][j][a][b]表示进行到第i个座位时已经有j个男生了,并且此时男-女的最大值为a,女-男的最大值为b。(这个最大值是由新增的座位后往前计算而得)
#include<iostream> #include<algorithm> #include<cstring> #include<cstdio> #include<vector> #include<stack> #include<queue> #include<cmath> #include<map> #include<set> using namespace std; typedef long long ll; typedef pair<int,int> pll; const int INF = 0x3f3f3f3f; const int maxn = 300+5; int n, m, k; int dp[maxn][155][25][25]; int main() { //freopen("in.txt","r",stdin); scanf("%d%d%d",&n,&m,&k); dp[0][0][0][0]=1; for(int i=0;i<n+m;i++) { for(int j=0;j<=n;j++) { for(int a=0;a<=k;a++) { for(int b=0;b<=k;b++) { if(a+1<=k && j+1<=n) dp[i+1][j+1][a+1][max(b-1,0)]=(dp[i+1][j+1][a+1][max(b-1,0)] + dp[i][j][a][b])%12345678; if(b+1<=k && i-j+1<=m) dp[i+1][j][max(a-1,0)][b+1]=(dp[i+1][j][max(a-1,0)][b+1] + dp[i][j][a][b])%12345678; } } } } int ans = 0; for(int a=0;a<=k;a++) { for(int b=0;b<=k;b++) { ans+=dp[n+m][n][a][b]; ans%=12345678; } } printf("%d ",ans); return 0; }