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[ ...
随机推荐
- bzoj1827 [Usaco2010 Mar]gather 奶牛大集会
不就是移一下树根,回溯一下吗? 诶?黄学长为什么可以直接找? 诶?这不是重心吗? YY了一下证明 很简单 由于重心max{sz[v]} <= sz[u] / 2的性质,可以证明每一步远离重心的移 ...
- php开发工具zendstudio13破解补丁
io? Intelligent Code Editor Robust Debugging Capabilities Eclipse Ecosystem Mobile: AngularJS, Ioni ...
- 《大话操作系统——做坚实的project实践派》(6)
继续写硬件体系.这个不写完.不会写操作系统内核.由于根基不正,则难于达到上层境地.
- lua字符匹配
匹配下列格式的数据中的 source和MAC地址: Chain WiFiDog_br-lan_Outgoing (1 references) pkts bytes target prot opt in ...
- 怎样让HTML5调用手机摄像头拍照——实践就是一切
原文:怎样让HTML5调用手机摄像头拍照--实践就是一切 NanShan 小编将思路提供给了大家.学编程最重要的是实践,我这尽管有完好的代码,可是希望大家都能够自己写出属于自己的代码 HTML5 Th ...
- InstallShield 12 制作安装包
目 录 一. 二. 三. (一) 打开project... 2 (二) project助手页面... 3 1.Application Information:程序信息... 4 2.Installa ...
- PHP面向对象之旅:模板模式(转)
抽象类的应用就是典型的模版模式 抽象类的应用就是典型的模版模式,先声明一个不能被实例化的模版,在子类中去依照模版实现具体的应用. 我们写这样一个应用: 银行计算利息,都是利率乘以本金和存款时间,但各种 ...
- spring aop 如何切面到mvc 的controller--转载
原文:http://yjian84.iteye.com/blog/1920787 网上搜罗半天,不知道什么原因,看了源码,好像他们说的controller 是不受代理的,也对哈,不知道怎么办,于是在h ...
- ipad itunes 恢复
http://jingyan.baidu.com/article/a3aad71aa58efbb1fa00967c.html http://act.feng.com/wetools/index.php ...
- oracle中的层级递归查询操作
oracle中的层级操作非常方便,在使用之后爱不释手,以前要实现该种数据查询操作,需要非常复杂的实现过程.在oracle中通过connect by可以实现前面的目的,通常情况下层级查询基本都能实现递归 ...