Caesar's Legions(三维dp)
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
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
2 1 1 10
1
2 3 1 2
5
2 4 1 1
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)的更多相关文章
- Codeforces118D Caesar's Legions(DP)
题目 Source http://codeforces.com/problemset/problem/118/D Description Gaius Julius Caesar, a famous g ...
- 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 ...
- 三维dp&codeforce 369_2_C
三维dp&codeforce 369_2_C 标签: dp codeforce 369_2_C 题意: 一排树,初始的时候有的有颜色,有的没有颜色,现在给没有颜色的树染色,给出n课树,用m种燃 ...
- P1006 传纸条(二维、三维dp)
P1006 传纸条 输入输出样例 输入 #1 复制 3 3 0 3 9 2 8 5 5 7 0 输出 #1 复制 34 说明/提示 [限制] 对于 30% 的数据,1≤m,n≤10: 对于 100% ...
- Codeforces 118 D. Caesar's Legions (dp)
题目链接:http://codeforces.com/contest/118/problem/D 有n个步兵和m个骑兵要排成一排,其中连续的步兵不能超过k1个,连续的骑兵不能超过k2个. dp[i][ ...
- 【dp】D. Caesar's Legions
https://www.bnuoj.com/v3/contest_show.php?cid=9146#problem/D [题意]给定n1个A,n2个B,排成一排,要求A最多能连续k1个紧挨着,B最多 ...
- Caesar's Legions(CodeForces-118D) 【DP】
题目链接:https://vjudge.net/problem/CodeForces-118D 题意:有n1名步兵和n2名骑兵,现在要将他们排成一列,并且最多连续k1名步兵站在一起,最多连续k2名骑兵 ...
- dp D. Caesar's Legions
https://codeforces.com/problemset/problem/118/D 这个题目有点思路,转移方程写错了. 这个题目看到数据范围之后发现很好dp, dp[i][j][k1][k ...
- codeforces118D. Caesar's Legions
地址:http://www.codeforces.com/problemset/problem/118/D 题目: Gaius Julius Caesar, a famous general, lov ...
随机推荐
- 安装.NET CORE
需要安装两个包 https://github.com/dotnet/cli 1. .NET Core Installer 2. .NET Core SDK Installer
- [BZOJ 2656][ZJOI2012]数列(递归+高精度)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=2656 分析: 很容易想到递归分治,但遇到奇数时候f[i]=f[i/2]+f[i/2+1 ...
- Bootstrap3.0学习第十五轮(大屏幕介绍、页面标题、缩略图、警示框、Well)
详情请查看 http://aehyok.com/Blog/Detail/22.html 个人网站地址:aehyok.com QQ 技术群号:206058845,验证码为:aehyok 本文文章链接:h ...
- 每天一个linux命令(22):chgrp命令
在 lunix系统里,文件或目录的权限的掌控以拥有者及所诉群组来管理.可以使用chgrp指令取变更文件与目录所属群组,这种方式采用群组名称或群组识别 码都可以.Chgrp命令就是change grou ...
- 第四次个人作业——关于微软必应词典android客户端的案例分析
[前言] 第一次搞测评这种东西,如果有什么疏漏,请多多谅解.测评内容如题. 第一部分 调研,评测 评测:(设备:Lenovo A806) 软件的bug,功能评测,黑箱测试 bug等级划分方式 5级分类 ...
- Ibatis学习总结4--SQL Map XML 映射文件扩展
SQL Map XML 映射文件除了上文提到的属性还有一些其他重要的属性,下文将详细介绍这些属性. 缓存 Mapped Statement 结果集 通过在查询 statement 中指定 cacheM ...
- java web中jsp,action,service,dao,po分别是什么意思和什么作用
JSP:全名为Java Server Pages,中文名叫java服务器页面,其根本是一个简化的Servlet设计,它[1] 是由Sun Microsystems公司倡导.许多公司参与一起建立的一种动 ...
- java.lang.NoClassDefFoundError: org/objectweb/asm/Type
Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/objectweb/asm/ ...
- Cas_Server端安装
一.Cas Server版本:3.5.2 下载地址:http://download.csdn.net/detail/xiaohuzi1987/5262980 二.安装步骤: 1.解压cas ...
- jQuery 文本编辑器插件 HtmlBox 使用
0.htmlbox下载地址:http://download.csdn.net/detail/leixiaohua1020/6376479 1.引入头文件 <script src="li ...