Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Submit Status

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 n1n2k1k2 (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

The problem is solved lazy dynamics. Let z[n1] [n2] [2] - a number of ways to place troops in a legion of Caesar. Indicate the following parameters, n1 – is a number of footmen, n2 – is a number of horseman, the third parameter indicates what troops put Caesar in the beginning of the line. If Caesar wants to put the footmen, the state dynamics of the z [n1] [n2] [0] go to the state

z [n1 - i] [n2] [0], where 0 <= i <= min (k1, n1) . If Caesar wants to put the riders, the state dynamics of the z [n1] [n2] [1] go to the state z [n1] [n2 - i] [1], where 0 <= I <= min (k2, n2) .

 #include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int mod = ;
int n1 , n2 , k1 , k2 ;
int a[][][] ; int Caesar (int n1 , int n2 , int f)
{
if (a[n1][n2][f] != - ) {
return a[n1][n2][f] ;
}
if (n1 + n2 == ) {
a[n1][n2][f] = % mod ;
return a[n1][n2][f] ;
}
a[n1][n2][f] = ;
int i ;
if (f == ) {
for (i = ; i <= min (k1 , n1 ) ; i++) {
a[n1][n2][f] += Caesar (n1 - i , n2 , - f) ;
a[n1][n2][f] %= mod ;
}
}
else {
for (i = ; i <= min (k2 , n2 ) ; i++) {
a[n1][n2][f] += Caesar (n1 , n2 - i , - f ) ;
a[n1][n2][f] %= mod ;
}
}
return a[n1][n2][f] ;
} void solve ()
{
memset (a , 0xFF , sizeof(a) ) ;
printf ("%d\n" , ( Caesar (n1 , n2 , ) + Caesar (n1 , n2 , ) ) % mod ) ;
} int main ()
{
#ifdef online_jude
freopen ("a.txt" , "r" , stdin ) ;
#endif // online_jude
scanf ("%d%d%d%d" , &n1 , &n2 , &k1 , &k2 ) ;
solve () ;
return ;
}

Caesar's Legions(三维dp)的更多相关文章

  1. Codeforces118D Caesar's Legions(DP)

    题目 Source http://codeforces.com/problemset/problem/118/D Description Gaius Julius Caesar, a famous g ...

  2. D. Caesar's Legions 背包Dp 递推DP

    http://codeforces.com/problemset/problem/118/D 设dp[i][j][k1][k2] 表示,放了i个1,放了j个2,而且1的连续个数是k1,2的连续个数是k ...

  3. 三维dp&codeforce 369_2_C

    三维dp&codeforce 369_2_C 标签: dp codeforce 369_2_C 题意: 一排树,初始的时候有的有颜色,有的没有颜色,现在给没有颜色的树染色,给出n课树,用m种燃 ...

  4. P1006 传纸条(二维、三维dp)

    P1006 传纸条 输入输出样例 输入 #1 复制 3 3 0 3 9 2 8 5 5 7 0 输出 #1 复制 34 说明/提示 [限制] 对于 30% 的数据,1≤m,n≤10: 对于 100% ...

  5. Codeforces 118 D. Caesar's Legions (dp)

    题目链接:http://codeforces.com/contest/118/problem/D 有n个步兵和m个骑兵要排成一排,其中连续的步兵不能超过k1个,连续的骑兵不能超过k2个. dp[i][ ...

  6. 【dp】D. Caesar's Legions

    https://www.bnuoj.com/v3/contest_show.php?cid=9146#problem/D [题意]给定n1个A,n2个B,排成一排,要求A最多能连续k1个紧挨着,B最多 ...

  7. Caesar's Legions(CodeForces-118D) 【DP】

    题目链接:https://vjudge.net/problem/CodeForces-118D 题意:有n1名步兵和n2名骑兵,现在要将他们排成一列,并且最多连续k1名步兵站在一起,最多连续k2名骑兵 ...

  8. dp D. Caesar's Legions

    https://codeforces.com/problemset/problem/118/D 这个题目有点思路,转移方程写错了. 这个题目看到数据范围之后发现很好dp, dp[i][j][k1][k ...

  9. codeforces118D. Caesar's Legions

    地址:http://www.codeforces.com/problemset/problem/118/D 题目: Gaius Julius Caesar, a famous general, lov ...

随机推荐

  1. jQuery ajax - get(),getJSON(),post()方法

    1)       jQuery ajax - get() 方法: $(selector).get(url,data,success(response,status,xhr),dataType) 参数 ...

  2. Boostrap(2)

    网页布局 1.网格布局 网格布局就是把网页分为许多小格子,看起来像table,然后在每个小格子中放我们的内容.当然,我们也可以指定一片区域使用网格系统.网格布局主要是应用在移动设备上的,使用方法如下: ...

  3. CsharpThinking---代码契约CodeContract(八)

    代码契约(Code Contract):它并不是语言本身的新功能,而是一些额外的工具,帮助人们控制代码边界. 代码契约之于C#,就相当于诗词歌赋之于语言. --- C# in Depth 一,概述 1 ...

  4. [设计模式] javascript 之 工厂方法模式

    1. 简单工厂模式 说明:就是创建一个工厂类,里面实现了所对同一个接口的实现类的创建. 但是好像JavaScript 好像没有 接口 这号东西,所以我们去掉接口这个层; 当然,我们这里的 实现类 下的 ...

  5. python 生成器

    摘自:http://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/00138681965108 ...

  6. LightOJ1348 树链剖分

    简单题,看题目就懂. #include<queue> #include<stack> #include<cmath> #include<cstdio> ...

  7. 图解Android - Android GUI 系统 (2) - 窗口管理 (View, Canvas, Window Manager)

    Android 的窗口管理系统 (View, Canvas, WindowManager) 在图解Android - Zygote 和 System Server 启动分析一 文里,我们已经知道And ...

  8. TCP/IP详解 学习二

    链路层: 在 T C P / I P协议族中,链路层主要有三个目的:(1)为 I P模块发送和接收 I P数据报:( 2)为 A R P模块发送 A R P请求和接收 A R P应答:( 3)为 R ...

  9. Exceptionless 本地部署

    免费开源分布式系统日志收集框架 Exceptionless 前两天看到了这篇文章,亲身体会了下,确实不错,按照官方的文档试了试本地部署,折腾一番后终于成功,记下心得在此,不敢独享. 本地部署官方wik ...

  10. STL Iterators

    Summary of Chapter 33 STL Iterators from The C++ Programming Language 4th. Ed., Bjarne Stroustrup. - ...