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[ ...
随机推荐
- 320. Generalized Abbreviation
首先想到的是DFS,对于每个单词的字母都遍历,比如 spy: 1py,s1y,sp1 然后每个遍历完的单词再DFS..左右有数字就合并比如 1py: 11y=>2py, 1p1 这样.. 但是单 ...
- Struts2和Struts1的不同
转载(没看懂) Action 类 ◆Struts1要求Action类继承一个抽象基类org.apache.struts.action.Action.Struts1的一个普遍问题是使用抽象类编程而不是接 ...
- 10.24 noip模拟试题
尼玛pdf依旧不会粘23333 /* 每段合并到总的里面 假设总的有X个 这一段有Y个 一共有X+1个空 那么就有 C(X+1,1)+C(X+1,2)+C(X+1,3)+...+C(X+1,Y) 这样 ...
- excel中VBA对多个文件的操作
添加引用 "Scripting.FileSystemObject" (Microsoft Scripting Runtime) '用于操作文件.目录 Sub 数据整理部分() ' ...
- oo面向对象原则
1.单一职责原则 一个类,最好只做一件事,只有一个引起他变化的原因否则就应该考虑重构. 2.开放封闭原则 软件实体应该是可扩展的,而不是可修改的.也就是说对扩展开放,对修改封闭.主要体现在两个方面: ...
- angularjs modal 嵌套modal的问题
anguarjs中当遇到modal嵌套modal的时候,比如一个modal弹出啦一个modal1,关闭modal1后,modal本身的关闭功能失效,那么需要$modal来生命弹出的modal1并且关闭 ...
- 微软企业库Microsoft Enterprise Library的相关文章链接
微软企业库4.1学习笔记 http://blog.csdn.net/anyqu/article/category/1228691/3 黄聪:Enterprise Library 5.0 系列教程 ww ...
- JS中escape 方法和C#中的对应
在项目中遇到js中escape过的json字符串,需要在C#中对应模拟编码,记得原来遇到过这个问题,但是当时没记录下来方案, 于是又搜索了一番,发现别人说的都是HttpUtility.UrlEncod ...
- Ubuntu系统中安装RPM格式包的方法
Ubuntu的软件包格式为deb,而RPM格式的包则是Red Hat 相关系统所用的软件包.当我们看到一个想用的软件包时,如果他是RPM格式,而你的操作系统是Ubuntu,那岂不是很遗憾?其实,在Ub ...
- Tensor神经网络进行知识库推理
本文是我关于论文<Reasoning With Neural Tensor Networks for Knowledge Base Completion>的学习笔记. 一.算法简介 网络的 ...