地址:http://www.codeforces.com/problemset/problem/118/D

题目:

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 beautifularrangements 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
input
2 4 1 1
output
0
Note

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

思路:好吧,这题又没自己做出来,看了别人的代码后才会的;

    开始我用dp[i][0]和dp[i][1]来表示前i个人中以0或1结尾的排列方式有多少中,然后。。。。就没有然后了,写不下去了,因为前i个人中,我统计不出步兵和骑兵各有多少人。

    。别人的做法:我只能说构思很巧!,算0结尾的用以1结尾的来计算!

  使用状态dp【i】【j】【k】,i,j:步兵,骑兵个数  k:0是步兵,1是骑兵

  状态方程:for(int k = 1; k <= min(i,k1); k++)
                  dp[i][j][0] = (dp[i][j][0] + dp[i-k][j][1])%MOD;
              for(int k = 1; k <= min(j,k2); k++)
                  dp[i][j][1] = (dp[i][j][1] + dp[i][j-k][0])%MOD;

 #include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <queue>
#include <stack>
#include <map>
#include <vector> #define PI acos((double)-1)
#define E exp(double(1))
using namespace std; int dp[][][];
int main (void)
{
int n1,n2,k1,k2;
cin>>n1>>n2>>k1>>k2;
memset(dp,,sizeof(dp));
for(int i=;i<= min(n1,k1);i++)
dp[i][][] = ;
for(int i = ;i<=min(n2,k2);i++)
dp[][i][]=;
for(int i = ;i<=n1;i++)
for(int j = ;j<=n2;j++)
{
for(int k=;k<=min(i,k1);k++)
dp[i][j][]=(dp[i][j][]+dp[i-k][j][])%;
for(int k=;k<=min(j,k2);k++)
dp[i][j][]=(dp[i][j][]+dp[i][j-k][])%;
}
cout<<(dp[n1][n2][]+dp[n1][n2][])%<<endl;
return ;
}

codeforces118D. Caesar's Legions的更多相关文章

  1. Codeforces118D Caesar's Legions(DP)

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

  2. Caesar's Legions(三维dp)

    Caesar's Legions Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u S ...

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

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

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

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

  5. 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 ...

  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. 【Codeforces 118B】Caesar's Legions

    [链接] 我是链接,点我呀:) [题意] 序列中不能连续出现k1个以上的1以及不能连续出现k2个以上的2,然后一共有n1个1以及n2和2,要求这n1+n2个数字都出现. 问序列有多少种可能. [题解] ...

  8. [CF118D]Caesar's Legions 题解

    题意简述 一个01序列由\(n_1\)个0和\(n_2\)个1组成,求最长连续0串长度不超过\(k_1\),最长连续1串长度不超过\(k_2\)的序列的方案总数 题解 状态 方案总数 变量 已经取了i ...

  9. D. Caesar's Legions

    \(状态很容易设计\) \(设dp[i][j][u][v]表示放了i个1兵种和j个2兵种\) \(然后u不会0说明末尾放了连续u个1兵种,v不为0说明末尾放了连续v个2兵种\) #include &l ...

随机推荐

  1. Face++ – 提供给你实时的脸部识别 API

    Face++ 是一个小巧,功能强大,跨平台的服务,由Megvii公司建立,致力于建立一个新的视觉平台.它使用计算机视觉尖端科技和数据挖掘,提供3个核心视觉服务(探测,识别和分析).基于 Face++ ...

  2. Page Scroll Effects - 简单的页面滚动效果

    Codyhouse 收集了一组页面滚动效果,就是目前大家很常见的用户在浏览网页的时候.一些效果虽然极端,但如果你的目标是创建一个身临其境的用户体验,他们是非常有用的.所有的动画都使用 Velocity ...

  3. js 中{},[]中括号,大括号使用详解

    一.{ } 大括号,表示定义一个对象,大部分情况下要有成对的属性和值,或是函数. 如:var LangShen = {"Name":"Langshen",&qu ...

  4. .Net关闭数据库连接时判断ConnectionState为Open还是Closed?

    两种写法: if (conn.State == System.Data.ConnectionState.Open)            {                conn.Close();  ...

  5. Kotlin语法(类和对象)

    二.类和对象: 1. 类定义: 类的声明包含类名,类头(指定类型参数,主构造函数等等),以及类主体,用大括号包裹.类头和类体是可选的:如果没有类体可以省略大括号. class Invoice{ } 2 ...

  6. System.Security.Cryptography.CryptographicException: 指定了无效的提供程序类型

    这两天在调用银联在线的支付接口,把银联提供的demo代码copy过来放到自己网站上,生成通过了,但是运行的时候就报错了: 指定了无效的提供程序类型. 说明: 执行当前 Web 请求期间,出现未经处理的 ...

  7. 【代码笔记】iOS-改变文字输入框背景

    一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...

  8. zh-Hans vs.net 通过 管理nuget程序包下载简体中文语言包 zh-cn

    zh-Hans  vs.net 通过 管理nuget程序包下载简体中文语言包 在搜索中输入:zh-hans

  9. IT软件开发常用英语词汇

    Aabstract 抽象的abstract base class (ABC)抽象基类abstract class 抽象类abstraction 抽象.抽象物.抽象性access 存取.访问access ...

  10. 使用T-SQL进行活动目录查询

    最近在某个项目中,需要针对TFS的用户按照所属的AD组来进行数据分析,但发现TFS中并没有存储用户所属的组信息,故考虑直接从AD中提取这个信息并存放在SQL Server的数据库表里面去. 经过一番G ...