您的位置:首页 > 其它

CodeForces 118D Caesar's Legions

2015-02-19 17:22 330 查看
Description

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.

Sample Input

Input
2 1 1 10


Output
1


Input
2 3 1 2


Output
5


Input
2 4 1 1


Output
0


Hint

Let's mark a footman as 1, and a horseman as 2.

In the first sample the only beautiful line-up is: 121
In the second sample 5 beautiful line-ups exist: 12122, 12212, 21212, 21221, 22121
动态规划还得好好研究研究

#include<iostream>  
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<string>
#include<string.h>
using namespace std;
const int maxn = 105;
const int base = 100000000;
int n, m, k1, k2, i, j, k, f[maxn][maxn][12][2], sum;

int main(){
	while (~scanf("%d%d%d%d", &n, &m, &k1, &k2))
	{
		memset(f, 0, sizeof(f));
		f[1][0][1][0] = 1;
		f[0][1][1][1] = 1;
		for (i = 0; i <= n;i++)
			for (j = 0; j <= m; j++)
			if (i + j >1)
			{
				for (k = 2; k <= k1; k++) 
					if (i) f[i][j][k][0] = f[i - 1][j][k - 1][0];
				for (k = 2; k <= k2; k++)
					if (j) f[i][j][k][1] = f[i][j - 1][k - 1][1];
				for (k = 1; k <= k2; k++) 
					if (i) f[i][j][1][0] = (f[i][j][1][0] + f[i - 1][j][k][1]) % base;
				for (k = 1; k <= k1; k++) 
					if (j) f[i][j][1][1] = (f[i][j - 1][k][0] + f[i][j][1][1]) % base;
			}
			for (sum = 0, i = 1; i <= max(k1, k2); i++) sum = (sum + f
[m][i][0] + f
[m][i][1]) % base;
			printf("%d\n", sum);
	}
	return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: