bzoj3864: Hero meet devil
Description
Input
Output
Sample Input
GTC
10
Sample Output
22783
528340
497452
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=;
const int maxm=;
const int maxstate=;
const int mod=;
const char dna[]={'A','C','G','T'};
char s[maxn];
int T,n,m,lim,cnt[maxstate];
int cur[maxn],g[maxn],trans[maxstate][],f[][maxstate],ans[maxn];
void work(){
for (int sta=;sta<lim;sta++){
for (int i=;i<=n;i++) cur[i]=cur[i-]+((sta>>(i-))&);
for (int c=;c<;c++){
for (int i=;i<=n;i++) g[i]=;
for (int i=;i<=n;i++){
g[i]=max(g[i-],cur[i]);
if (s[i]==dna[c]) g[i]=max(g[i],cur[i-]+);
}
int res=;
for (int i=;i<=n;i++) if (g[i]>g[i-]) res|=(<<(i-));
trans[sta][c]=res;
}
}
memset(f[],,sizeof(f[]));
f[][]=;
for (int i=;i<=m;i++){
memset(f[i&],,sizeof(f[i&]));
for (int sta=;sta<lim;sta++) if (f[(i-)&][sta])
for (int c=;c<;c++) f[i&][trans[sta][c]]+=f[(i-)&][sta],f[i&][trans[sta][c]]%=mod;
}
memset(ans,,sizeof(ans));
for (int sta=;sta<lim;sta++) ans[cnt[sta]]+=f[m&][sta],ans[cnt[sta]]%=mod;
for (int i=;i<=n;i++) printf("%d\n",ans[i]);
}
int main(){
for (int i=;i<;i++) cnt[i]=cnt[i&(i-)]+;
for (scanf("%d",&T);T;T--) scanf("%s%d",s+,&m),n=strlen(s+),lim=<<n,work();
return ;
}
bzoj3864: Hero meet devil的更多相关文章
- BZOJ3864: Hero meet devil(dp套dp)
Time Limit: 8 Sec Memory Limit: 128 MBSubmit: 397 Solved: 206[Submit][Status][Discuss] Description ...
- BZOJ3864: Hero meet devil【dp of dp】
Description There is an old country and the king fell in love with a devil. The devil always asks th ...
- bzoj千题计划241:bzoj3864: Hero meet devil
http://www.lydsy.com/JudgeOnline/problem.php?id=3864 题意: 给你一个DNA序列,求有多少个长度为m的DNA序列和给定序列的LCS为0,1,2... ...
- 【BZOJ3864】Hero meet devil DP套DP
[BZOJ3864]Hero meet devil Description There is an old country and the king fell in love with a devil ...
- bzoj 3864: Hero meet devil [dp套dp]
3864: Hero meet devil 题意: 给你一个只由AGCT组成的字符串S (|S| ≤ 15),对于每个0 ≤ .. ≤ |S|,问 有多少个只由AGCT组成的长度为m(1 ≤ m ≤ ...
- BZOJ3864 & HDU4899:Hero meet devil——题解
https://www.lydsy.com/JudgeOnline/problem.php?id=3864 http://acm.hdu.edu.cn/showproblem.php?pid=4899 ...
- HDU 4899 Hero meet devil(状压DP)(2014 Multi-University Training Contest 4)
Problem Description There is an old country and the king fell in love with a devil. The devil always ...
- HDU 4899 Hero meet devil (状压DP, DP预处理)
题意:给你一个基因序列s(只有A,T,C,G四个字符,假设长度为n),问长度为m的基因序列s1中与给定的基因序列LCS是0,1......n的有多少个? 思路:最直接的方法是暴力枚举长度为m的串,然后 ...
- bzoj 3864: Hero meet devil
bzoj3864次元联通们 第一次写dp of dp (:з」∠) 不能再颓废啦 考虑最长匹配序列匹配书转移 由于dp[i][j]的转移可由上一行dp[i-1][j-1],dp[i-1][j],dp[ ...
随机推荐
- 【MySQL性能优化】改进MySQL Order By Rand()的低效率
<a href="http://click.aliyun.com/m/9153/">点击查看原文</a> 正 文: 最近由于需要研究了一下MYSQL的随 ...
- disconf实践(二)
因为有些系统的配置文件会随着业务更改,如某些控制开关,当大批量集群时,按照上一篇文章的配置就不够啦,需要做到热加载. 研究了一下,还好,比较简单,只要替换上一篇文章第4步的配置文件(spring-di ...
- BZOJ 1835: [ZJOI2010]base 基站选址 [序列DP 线段树]
1835: [ZJOI2010]base 基站选址 题目描述 有N个村庄坐落在一条直线上,第i(i>1)个村庄距离第1个村庄的距离为Di.需要在这些村庄中建立不超过K个通讯基站,在第i个村庄建立 ...
- linux系统启动oracle
linux下启动oracle需要两步:一.启动监听 二.启动服务 一.启动监听 监听命令:lsnrctl ,具体使用方法如下 1.lsnrctl status:检查当前监听器的状态 2.lsnrct ...
- 【ActionScript】ActionScript3.0对舞台组件的增删改查
以一个样例来说明ActionScript3.0对舞台组件的增删改查 例如以下图: 在Flash执行的时候,通过脚本.斜向下生成text0-text9十个文本节点. 提供两个功能. 1.在右上角,用户输 ...
- ajax jsonp跨域处理问题
客户端 html $.ajax({ type : "get", async:false, dataType : "jsonp", jsonp: "js ...
- [React] React Fundamentals: with-addons - ReactLink
It can be tedious to type out all the boilerplate needed to get the DOM and states in React to synch ...
- 写一个函数,参数为$n,生成一个数组,其元素为1~$n,各元素位置随机排列,不得重复
function rand_array($n){ $array=range(1,$n); shuffle($array); return $array; }
- Hive数据导入
可以通过多种方式将数据导入hive表 1.通过外部表导入 用户在hive上建external表,建表的同时指定hdfs路径,在数据拷贝到指定hdfs路径的同时,也同时完成数据插入external表. ...
- 史上最全WebView使用,附送Html5Activity一份
本文来自:http://www.jianshu.com/users/320f9e8f7fc9/latest_articles感谢您的关注. WebView在现在的项目中使用的频率应该还是非常高的.我个 ...