题意简述

一个01序列由\(n_1\)个0和\(n_2\)个1组成,求最长连续0串长度不超过\(k_1\),最长连续1串长度不超过\(k_2\)的序列的方案总数

题解

状态

方案总数

变量

已经取了i个0,j个1,当前末尾连续串长度为k,末尾为l。

转移

\[f[i][j][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 题解的更多相关文章

  1. Caesar's Legions(三维dp)

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

  2. Codeforces118D Caesar's Legions(DP)

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

  3. codeforces118D. Caesar's Legions

    地址:http://www.codeforces.com/problemset/problem/118/D 题目: Gaius Julius Caesar, a famous general, lov ...

  4. 【Codeforces 118B】Caesar's Legions

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

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

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

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

  7. 【dp】D. Caesar's Legions

    https://www.bnuoj.com/v3/contest_show.php?cid=9146#problem/D [题意]给定n1个A,n2个B,排成一排,要求A最多能连续k1个紧挨着,B最多 ...

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

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

  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. reactstrap,scrollbar组件

    react-script 编译,部署,sass,less,test,helmet等 https://github.com/facebookincubator/create-react-app/blob ...

  2. [JS] 文本框判断输入的内容是否为数字

    可以通过触发文本框的onchange事件来对输入的内容进行判断是否为数字 文本框的属性设置: 把onchange的属性对应的js函数写好即可 参数传输的是当前控件的value值,即text值 < ...

  3. PostgreSQL逻辑复制到kafka-实践

    kafka 安装 wget http://mirror.bit.edu.cn/apache/kafka/2.3.0/kafka_2.12-2.3.0.tgz cp kafka_2.12-2.0.1.t ...

  4. <<C++ Primer>> 第三章 字符串, 向量和数组 术语表

    术语表 第 3 章 字符串, 向量和数组 begin: 是 string 和 vector 的成员,返回指向第一个元素的迭代器.也是一个标准库函数,输入一个数字,返回指向该数字首元素的指针.    缓 ...

  5. Python字符串和正则表达式中的反斜杠('\')问题

    在Python普通字符串中 在Python中,我们用'\'来转义某些普通字符,使其成为特殊字符,比如 In [1]: print('abc\ndef') # '\n'具有换行的作用 abc defg ...

  6. transition 带的参数什么意思

    过渡transition:属性名  过渡效果时间 时间速度曲线  开始时间        默认值:    all              0                            e ...

  7. 学习WPF-1

    学习WPF-1 最近到新公司,需要使用WPF来做界面开发,我原先是使用WinForm来做界面开发的,所以对于现在使用WPF来开发,需要先学习一段时间了,考核的内容目前也还没定下来做什么, 但终归是使用 ...

  8. C++ 大数运算(加减乘除取模)

    加法:(字符串模拟小学加法) string add(string s1, string s2) { int len1 = s1.length(), len2 = s2.length(); ; '); ...

  9. oracle函数nvl,nvl2的区别,nullif函数,coalesce函数

    在oracle中用nvl和nvl2函数来解决为空的情况,例如,如果奖金为空,则为它指定一个数.也就是nvl(奖金字段,指定的奖金),但是两个的类型要一致. 1)nvl()函数 SQL> sele ...

  10. alembic 实践操作

    1. alembic [--config */alembic.ini ] current 2. alembic revision -m "add columns" 编辑生产的模板文 ...