Codeforces 118 D. Caesar's Legions (dp)
题目链接:http://codeforces.com/contest/118/problem/D
有n个步兵和m个骑兵要排成一排,其中连续的步兵不能超过k1个,连续的骑兵不能超过k2个。
dp[i][j][x][y]表示表示用i个步兵和j个骑兵,末尾有连续的x个步兵,或者有连续的y个骑兵。
所以x > 0 && y > 0的情况不存在。三个for就好了。
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL mod = 1e8;
LL dp[][][][];
int main()
{
int n, m, k1, k2;
cin >> n >> m >> k1 >> k2;
dp[][][][] = ;
for(int i = ; i <= n; ++i) {
for(int j = ; j <= m; ++j) {
if(j < m) {
for(int x = ; x <= k1; ++x) {
dp[i][j + ][][] += dp[i][j][x][];
dp[i][j + ][][] %= mod;
}
}
if(i < n) {
for(int x = ; x <= k2; ++x) {
dp[i + ][j][][] += dp[i][j][][x];
dp[i + ][j][][] %= mod;
}
}
if(i < n) {
for(int x = ; x < k1; ++x) {
dp[i + ][j][x + ][] += dp[i][j][x][];
dp[i + ][j][x + ][] %= mod;
}
}
if(j < m) {
for(int x = ; x < k2; ++x) {
dp[i][j + ][][x + ] += dp[i][j][][x];
dp[i][j + ][][x + ] %= mod;
}
}
}
}
LL ans = ;
for(int i = ; i <= k1; ++i) {
ans = (ans + dp[n][m][i][]) % mod;
}
for(int i = ; i <= k2; ++i) {
ans = (ans + dp[n][m][][i]) % mod;
}
cout << ans << endl;
return ;
}
Codeforces 118 D. Caesar's Legions (dp)的更多相关文章
- 【Codeforces 118B】Caesar's Legions
[链接] 我是链接,点我呀:) [题意] 序列中不能连续出现k1个以上的1以及不能连续出现k2个以上的2,然后一共有n1个1以及n2和2,要求这n1+n2个数字都出现. 问序列有多少种可能. [题解] ...
- Caesar's Legions(三维dp)
Caesar's Legions Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u S ...
- [Codeforces 865C]Gotta Go Fast(期望dp+二分答案)
[Codeforces 865C]Gotta Go Fast(期望dp+二分答案) 题面 一个游戏一共有n个关卡,对于第i关,用a[i]时间通过的概率为p[i],用b[i]通过的时间为1-p[i],每 ...
- [CodeForces - 1225E]Rock Is Push 【dp】【前缀和】
[CodeForces - 1225E]Rock Is Push [dp][前缀和] 标签:题解 codeforces题解 dp 前缀和 题目描述 Time limit 2000 ms Memory ...
- [Codeforces 553E]Kyoya and Train(期望DP+Floyd+分治FFT)
[Codeforces 553E]Kyoya and Train(期望DP+Floyd+分治FFT) 题面 给出一个\(n\)个点\(m\)条边的有向图(可能有环),走每条边需要支付一个价格\(c_i ...
- 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 D. Caesar's Legions
https://codeforces.com/problemset/problem/118/D 这个题目有点思路,转移方程写错了. 这个题目看到数据范围之后发现很好dp, dp[i][j][k1][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最多 ...
随机推荐
- jsp 三大指令和动作标签
jsp三大指令 一个jsp页面中可以有0-N个指令 1.page--->最复杂:<%@page language="" ...%> *pageEncoding和c ...
- PS4破解
1.输入序列号: # 序列号: # 1330-1082-3503-2270-3738-6738# 1330-1776-8671-6289-7706-2916# 1330-1567-6599-8775- ...
- (六)6.10 Neurons Networks implements of softmax regression
softmax可以看做只有输入和输出的Neurons Networks,如下图: 其参数数量为k*(n+1) ,但在本实现中没有加入截距项,所以参数为k*n的矩阵. 对损失函数J(θ)的形式有: 算法 ...
- foreach的指针问题
从代码: $arr = array(,,,,); echo '$arr = array(1,2,3,4,5)','<br>'; foreach($arr as $key => &am ...
- 通过外部接口 根据ip获取城市名
3种接口 淘宝/百度/不知名/ 推荐淘宝接口 ip自个去获取,下附带php 获取ip的示例 function getIP() { static $realip; if (isset($_SERVE ...
- 安装sass时,gem在国内不能安装的解决
最近在安装SASS的时候,用到gem命令,但是运行出行如下错误!(先声明,安装sass前,要保证自己电脑安装了ruby:ruby -v可以测试下有没有装) 原因是ruby 的gem被和谐了,现在淘宝的 ...
- geotools导出shapefile出错: java.io.IOException: Current fid index is null, next must be called before write()
geotools导出shapefile出错: java.io.IOException: Current fid index is null, next must be called before wr ...
- smarty缓存函数
原来在Smarty中在3.0以上版本中不在使用这个clear_all_cache(),而是以$smarty->clearAllCache(); 代替.其中$smarty->clear_ca ...
- svn log 不显示日志的问题
在你配好了Xcode里的SourceControl之后提交代码回复代码都很方便,可是为什么在Xcode上提交的log,在svn下面显示不出来! 解决办法是:在命令行下,先 svn update 一下, ...
- XRPictureBox z
XRPictureBox 大小加入是40x40 我绑定的图片好比是60X50 , 在不自己写代码的情况下,XRPictureBox 有没有什么属性可以调整,比如像SizeMode那种? // Set ...