[CF118D]Caesar's Legions 题解
题意简述
一个01序列由\(n_1\)个0和\(n_2\)个1组成,求最长连续0串长度不超过\(k_1\),最长连续1串长度不超过\(k_2\)的序列的方案总数
题解
状态
方案总数
变量
已经取了i个0,j个1,当前末尾连续串长度为k,末尾为l。
转移
\left\{
\begin{matrix}
\sum_{x=1}^{min(j,k_2)} f[i-[l=0]][j-[l=1]][x][l\ xor\ 1] && k = 1\\
f[i-[l=0]][j-[l=1]][k-1][l] && k > 1\\
\end{matrix}
\right.
\]
注:\([i=1]\)意为在\(i=1\)时值为\(1\),否则值为\(0\)。
代码
#include <cstdio>
#include <algorithm>
using namespace std;
const long long MOD = 100000000;
namespace fast_IO{
const int IN_LEN = 10000000, OUT_LEN = 10000000;
char ibuf[IN_LEN], obuf[OUT_LEN], *ih = ibuf + IN_LEN, *oh = obuf, *lastin = ibuf + IN_LEN, *lastout = obuf + OUT_LEN - 1;
inline char getchar_(){return (ih == lastin) && (lastin = (ih = ibuf) + fread(ibuf, 1, IN_LEN, stdin), ih == lastin) ? EOF : *ih++;}
inline void putchar_(const char x){if(oh == lastout) fwrite(obuf, 1, oh - obuf, stdout), oh = obuf; *oh ++= x;}
inline void flush(){fwrite(obuf, 1, oh - obuf, stdout);}
int read(){
int x = 0; int zf = 1; char ch = ' ';
while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar_();
if (ch == '-') zf = -1, ch = getchar_();
while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar_(); return x * zf;
}
void write(int x){
if (x < 0) putchar_('-'), x = -x;
if (x > 9) write(x / 10);
putchar_(x % 10 + '0');
}
}
using namespace fast_IO;
long long f[105][105][11][2];
int main(){
int n1 = read(), n2 = read(), k1 = read(), k2 = read();
for (int i = 1; i <= k1; ++i) f[i][0][i][0] = 1;
for (int i = 1; i <= k2; ++i) f[0][i][i][1] = 1;
for (int i = 1; i <= n1; ++i)
for (int j = 1; j <= n2; ++j){
for (int k = 1; k <= min(j, k2); ++k)
(f[i][j][1][0] += f[i - 1][j][k][1]) %= MOD;
for (int k = 1; k <= min(i, k1); ++k)
(f[i][j][1][1] += f[i][j - 1][k][0]) %= MOD;
for (int k = 2; k <= min(i, k1); ++k)
(f[i][j][k][0] += f[i - 1][j][k - 1][0]) %= MOD;
for (int k = 2; k <= min(j, k2); ++k)
(f[i][j][k][1] += f[i][j - 1][k - 1][1]) %= MOD;
}
long long ans = 0;
for (int i = 1; i <= 10; ++i)
(ans += f[n1][n2][i][0] + f[n1][n2][i][1]) %= MOD;
printf("%lld", ans);
return 0;
}
[CF118D]Caesar's Legions 题解的更多相关文章
- Caesar's Legions(三维dp)
Caesar's Legions Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u S ...
- Codeforces118D Caesar's Legions(DP)
题目 Source http://codeforces.com/problemset/problem/118/D Description Gaius Julius Caesar, a famous g ...
- codeforces118D. Caesar's Legions
地址:http://www.codeforces.com/problemset/problem/118/D 题目: Gaius Julius Caesar, a famous general, lov ...
- 【Codeforces 118B】Caesar's Legions
[链接] 我是链接,点我呀:) [题意] 序列中不能连续出现k1个以上的1以及不能连续出现k2个以上的2,然后一共有n1个1以及n2和2,要求这n1+n2个数字都出现. 问序列有多少种可能. [题解] ...
- 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最多 ...
- Caesar's Legions(CodeForces-118D) 【DP】
题目链接:https://vjudge.net/problem/CodeForces-118D 题意:有n1名步兵和n2名骑兵,现在要将他们排成一列,并且最多连续k1名步兵站在一起,最多连续k2名骑兵 ...
- D. Caesar's Legions
\(状态很容易设计\) \(设dp[i][j][u][v]表示放了i个1兵种和j个2兵种\) \(然后u不会0说明末尾放了连续u个1兵种,v不为0说明末尾放了连续v个2兵种\) #include &l ...
随机推荐
- TCP listener
调试时未关闭之前开启的TCP SERVER: 应该关闭: TcpListener TcpClient 1.开启TCP listener (1)Start()方法失败 异常位置:该异常的产生位置为 tc ...
- Statistics项目学习笔记
1. http://218.244.157.0:55443/index.html 初始访问时,弹出的窗口为index.html文件,文件有html命令组成.html展现的UI界面用的是WIN10-UI ...
- Windown Server 2008配置tomcat9虚拟路径
一.用途 用于保存项目运产生的文件 二.步骤 1.修改conf\下的web.xml <!-- 找到listings将false改为true --> <init-para ...
- Git+码云安装
注册码云 1.1 下载git https://git-scm.com 1.2 安装 git安装一直next 下一步就行 1.3 测试 1.4 git原理
- Codeforces893F_Subtree Minimum Query
题意 给定一棵树和根,每个点有点权,强制在线询问\(x\)子树里离\(x\)距离不超过\(k\)的最小点权. 分析 权值线段树合并的套路题,dfs,以深度作为下标,点权作为值,对每个点建立一颗权值线段 ...
- 由对称性解2-SAT问题
由对称性解2-SAT问题 (by 伍昱,03年IOI国家集训队论文ppt) 2-SAT: 2-SAT就是2判定性问题,是一种特殊的逻辑判定问题. 2-SAT问题有何特殊性?该如何求解? 我们从一道例题 ...
- C语言中将二维数组作为函数参数来传递
c语言中经常需要通过函数传递二维数组,有三种方法可以实现,如下: 方法一, 形参给出第二维的长度. 例如: #include <stdio.h> void func(int n, char ...
- Spring Boot缓存注解@Cacheable、@CacheEvict、@CachePut使用
从3.1开始,Spring引入了对Cache的支持.其使用方法和原理都类似于Spring对事务管理的支持.Spring Cache是作用在方法上的,其核心思想是这样的:当我们在调用一个缓存方法时会把该 ...
- 解决Linux下SSH超时自动断开
title: 解决Linux下SSH超时自动断开 comments: false date: 2019-08-19 19:22:55 description: Linux 下 SSH 超时自动断开?? ...
- 使用CXF开发WebService程序的总结(三):创建webservice客户端
1.创建一个maven子工程 ws_client,继承父工程 1.1 修改父工程pom配置 <modules> <module>ws_server</module> ...