题意简述

一个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;
}

最新文章

  1. ActivityGroup、TabHost之子页面不刷新——getLocalActivityManager() 以及intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)用法
  2. js020-JSON
  3. android之网络操作(1)
  4. Codeforces 86C Genetic engineering(AC自动机+DP)
  5. 《C和指针》读书笔记——第五章 操作符和表达式
  6. JS之路——浏览器window对象
  7. SQL Server 与 Windows 内存使用上的约定
  8. shapefile 编码错误问题解决 Wrong codepage of shapefile Warning 1: One or several characters couldn&#39;t be converted correctly from UTF-8 to ISO-8859-1.
  9. eclipse代码提示配置
  10. 常用PHP函数的封装
  11. 呵呵哒,LNMP下通过fread方式下载文件时,中文名称文件找不到文件
  12. 蓝桥杯 求最大值 dp
  13. [Swift]LeetCode1034.边框着色 | Coloring A Border
  14. HSmartWindowControl之安装篇 (Visual Studio 2013 &amp; Halcon 18)
  15. 8. Filters in ASP.NET MVC 5.0【ASP.NET MVC 5.0中的过滤器】
  16. python 中range函数的用法
  17. go学习 --- Chan (通道)
  18. Python量化常用函数
  19. libevent学习六(Connect listeners )
  20. U-Boot启动过程完全分析&lt;转&gt;

热门文章

  1. linux whoami 显示当前用户的用户名
  2. CF486B OR in Matrix(构造+思维)
  3. PostgreSQL通过解析日志,获取数据库增量变化,pg_recvlogical
  4. redis 小结 一
  5. 使用python 实现 微信好友 个性签名 并 制作 词云图
  6. vue项目报错1 Vue is a constructor and should be called with the `new` keyword &amp;&amp; jquery.js?eedf:3850 Uncaught TypeError: this._init is not a function...
  7. CSS3 @keyframes 实现匀速旋转魔方(搬运工)
  8. hbase权限控制
  9. java面试题全集(上)
  10. tomcat同个端口配置多个项目后无后缀的页面跳转