D. Caesar's Legions
time limit per test 2 seconds
memory limit per test 256 megabytes
input standard input
output standard output
Gaius Julius Caesar, a famous general, loved to line up his soldiers. Overall the army had n1 footmen and n2 horsemen. Caesar thought that an arrangement is not beautiful if somewhere in the line there are strictly more that k1 footmen standing successively one after another, or there are strictly more than k2 horsemen standing successively one after another. Find the number of beautiful arrangements of the soldiers.
Note that all n1 + n2 warriors should be present at each arrangement. All footmen are considered indistinguishable among themselves. Similarly, all horsemen are considered indistinguishable among themselves.
Input
The only line contains four space-separated integers n1, n2, k1, k2 (1 ≤ n1, n2 ≤ 100, 1 ≤ k1, k2 ≤ 10) which represent how many footmen and horsemen there are and the largest acceptable number of footmen and horsemen standing in succession, correspondingly.
Output
Print the number of beautiful arrangements of the army modulo 100000000 (108). That is, print the number of such ways to line up the soldiers, that no more than k1 footmen stand successively, and no more than k2 horsemen stand successively.
Examples
input
2 1 1 10
output
1
input
2 3 1 2
output
5
题意:n个0,m个1,问有多少种排列方式满足连续的0不超过a个,连续的1不超过b个
dp[x][y][z] = 前x个数中有y个1,并且最后一个数是z的方案数
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<map>
#include<string>
#include<math.h>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
#define LL long long
#define mod 100000000
LL dp[205][105][2];
int main(void)
{
int n, m, a, b, i, j, k;
scanf("%d%d%d%d", &n, &m, &a, &b);
n = n+m, dp[0][0][1] = dp[0][0][0] = 1;
for(i=1;i<=n;i++)
{
for(j=0;j<=m;j++)
{
for(k=i-1;k>=max(i-a,0);k--)
dp[i][j][0] = (dp[i][j][0]+dp[k][j][1])%mod;
for(k=i-1;k>=max(i-b,max(i-j,0));k--)
dp[i][j][1] = (dp[i][j][1]+dp[k][j-(i-k)][0])%mod;
}
}
printf("%lld\n", (dp[n][m][0]+dp[n][m][1])%mod);
return 0;
}