http://www.lydsy.com/JudgeOnline/problem.php?id=1037
题意:
思路:
四维数组进行dp,dp[i][j][a][b]表示进行到第i个座位时已经有j个男生了,并且此时男-女的最大值为a,女-男的最大值为b。(这个最大值是由新增的座位后往前计算而得)
1 #include<iostream> 2 #include<algorithm> 3 #include<cstring> 4 #include<cstdio> 5 #include<vector> 6 #include<stack> 7 #include<queue> 8 #include<cmath> 9 #include<map> 10 #include<set> 11 using namespace std; 12 typedef long long ll; 13 typedef pair<int,int> pll; 14 const int INF = 0x3f3f3f3f; 15 const int maxn = 300+5; 16 17 int n, m, k; 18 int dp[maxn][155][25][25]; 19 20 int main() 21 { 22 //freopen("in.txt","r",stdin); 23 scanf("%d%d%d",&n,&m,&k); 24 dp[0][0][0][0]=1; 25 for(int i=0;i<n+m;i++) 26 { 27 for(int j=0;j<=n;j++) 28 { 29 for(int a=0;a<=k;a++) 30 { 31 for(int b=0;b<=k;b++) 32 { 33 if(a+1<=k && j+1<=n) 34 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; 35 if(b+1<=k && i-j+1<=m) 36 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; 37 } 38 } 39 } 40 } 41 int ans = 0; 42 for(int a=0;a<=k;a++) 43 { 44 for(int b=0;b<=k;b++) 45 { 46 ans+=dp[n+m][n][a][b]; 47 ans%=12345678; 48 } 49 } 50 printf("%d\n",ans); 51 return 0; 52 }