codeforces118D. Caesar's Legions
地址: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.
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.
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.
2 1 1 10
1
2 3 1 2
5
2 4 1 1
0
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的更多相关文章
- Codeforces118D Caesar's Legions(DP)
题目 Source http://codeforces.com/problemset/problem/118/D Description Gaius Julius Caesar, a famous g ...
- Caesar's Legions(三维dp)
Caesar's Legions Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u S ...
- Caesar's Legions(CodeForces-118D) 【DP】
题目链接:https://vjudge.net/problem/CodeForces-118D 题意:有n1名步兵和n2名骑兵,现在要将他们排成一列,并且最多连续k1名步兵站在一起,最多连续k2名骑兵 ...
- Codeforces 118 D. Caesar's Legions (dp)
题目链接:http://codeforces.com/contest/118/problem/D 有n个步兵和m个骑兵要排成一排,其中连续的步兵不能超过k1个,连续的骑兵不能超过k2个. dp[i][ ...
- 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】D. Caesar's Legions
https://www.bnuoj.com/v3/contest_show.php?cid=9146#problem/D [题意]给定n1个A,n2个B,排成一排,要求A最多能连续k1个紧挨着,B最多 ...
- 【Codeforces 118B】Caesar's Legions
[链接] 我是链接,点我呀:) [题意] 序列中不能连续出现k1个以上的1以及不能连续出现k2个以上的2,然后一共有n1个1以及n2和2,要求这n1+n2个数字都出现. 问序列有多少种可能. [题解] ...
- [CF118D]Caesar's Legions 题解
题意简述 一个01序列由\(n_1\)个0和\(n_2\)个1组成,求最长连续0串长度不超过\(k_1\),最长连续1串长度不超过\(k_2\)的序列的方案总数 题解 状态 方案总数 变量 已经取了i ...
- D. Caesar's Legions
\(状态很容易设计\) \(设dp[i][j][u][v]表示放了i个1兵种和j个2兵种\) \(然后u不会0说明末尾放了连续u个1兵种,v不为0说明末尾放了连续v个2兵种\) #include &l ...
随机推荐
- 实例之JavaScript
使用JavaScript实现5秒倒计时 <html> <head> <meta charset="utf-8"> <title>&l ...
- 安装 Ubuntu 后的个人常用配置
在 ASA 猪队友的带领下,拥抱开源世界,用上了Ubuntu.资深强迫症现身说法,配置符合自己使用习惯的Ubuntu. 1. 窗口标题栏显示菜单项 打开系统设置->外观->行为,在[显示窗 ...
- 关于SAP的事务提交和回滚(LUW)
1 Sap的更新的类型 在sap中,可以使用CALL FUNCTION ... IN UPDATE TASK将多个数据更新绑定到一个database LUW中.程序使用COMMIT WORK提交修改请 ...
- .NET破解之图片下载器
自去年五月加入吾爱后,学习了三个月,对逆向破解产生了深厚的兴趣,尤其是对.NET方面的分析:但由于这一年,项目比较忙,事情比较多,破解这方面又停滞了许久,不知道还要好久. 前些天,帮忙批量下载QQ相册 ...
- ora-00119和ora-00132解决方案
win7 64位 oracle 11g 先登录到sqlplus: sqlplus /nolog; 登录数据库: conn system/manager as sysdba; 然后启动数据库: ...
- unbuntu apahce 2 设置 多域名
1.找到apache2 的设置路径 默认的apache的路径为/etc/apache2/ 2. 修改httpd.conf 本文192.168.0.1 为自己的服务器的ip,下面一样的意思 Server ...
- 论使用LeanCloud中遇到的坑
1.短信验证码 当注册用户的时候,会发现收不到短信验证码,打印e : That operation isn't allowed for clients. 含义 - 该操作无法从客户端发起.请检查该错误 ...
- NSJSONSerialization
/* 总结: json格式的读写: 解析: data = NSData dataWithContentsOfUrl:XXX id obj = [ NSJsonSerializat ...
- Web应用程序系统的多用户权限控制设计及实现-页面模块【9】
前五章均是从整体上讲述了Web应用程序的多用户权限控制实现流程,本章讲述Web权限管理系统的基本模块-页面模块.页面模块涉及到的数据表为页面表. 1.1页面域 为了更规范和方便后期系统的二次开发和维护 ...
- [在线] html 转 pdf
http://www.htm2pdf.co.uk/