bzoj3864次元联通们

第一次写dp of dp (:з」∠) 不能再颓废啦

考虑最长匹配序列匹配书转移

由于dp[i][j]的转移可由上一行dp[i-1][j-1],dp[i-1][j],dp[i][j-1]得来

把dp[i]差分,得到一个01串

就可以用rans[s][ch]表示在状态s的dp数组后面接字符ch可以转移到的状态

枚举该转移就好了QAQ

/**************************************************************
Problem: 3864
Language: C++
Result: Accepted
Time:4208 ms
Memory:2356 kb
****************************************************************/
//f[i]为之前前i项的LCS,g[i]为添加字母之后的
//g数组的差值就是下一次匹配转移到的状态
#include<cstdio>
#include<cstring>
#include<algorithm>
using std::memset;
const int mod= 1000000007;
inline int read() {
int x=0,f=1;
char c=getchar() ;
while(c<'0'||c>'9') {
if(c=='-')f=-1;
c=getchar();
}
while(c<='9'&&c>='0') {
x=x*10+c-'0';
c=getchar();
}
return x*f;
}const int maxn = 16;
int cnt,m,n;
char a[40];
int tans[1<<maxn][4];
int ans[2][1<<maxn],f[maxn],g[maxn];
int is[maxn];
int s[maxn];
void network(int maxx) {
int now=1;
memset(ans,0,sizeof ans);
ans[0][0]=1;
for(int i=1;i<=m;++i,now=i&1) {
for(int j=0;j<4;++j)
for(int e=0;e<maxx;++e)
ans[now][tans[e][j]]=(ans[now][tans[e][j]]+ans[now^1][e])%mod;
memset(ans[now^1],0,sizeof ans[now^1]);
//now=i&1;
}
now^=1;
memset(is,0,sizeof is);
for(int i=0;i<maxx;++i) is[__builtin_popcount(i)]=(is[__builtin_popcount(i)]+ans[now][i])%mod;
for(int i=0;i<=n;++i)printf("%d\n",is[i]);
}
void solve(int m,int n) {
int maxx=1<<n;
for(int i=0;i<maxx;++i) {
f[0]=i&1;
for(int j=1;j<n;++j) f[j]=((i>>j)&1)+f[j-1];
for(int j=0;j<4;++j) {
memset(g,0,sizeof g);
for(int e=0;e<n;++e) {
if(s[e]==j) g[e] = f[e-1]+1;//最后一位与原来匹配
else g[e]=std::max(g[e-1],f[e]);
}
int tmp = 0;
for(int e=0;e<n;++e)
if(g[e]==g[e-1]+1)
tmp|=1<<e;
tans[i][j]=tmp;
}
}
network(maxx);
}
int main() {
cnt=read();
for(int i=1;i<=cnt;++i) {
scanf("%s",a);
m=read();n=strlen(a);
for(int i=0;i<n;++i)
if(a[i]=='A') s[i]=0;
else if(a[i]=='T') s[i]=1;
else if(a[i]=='C') s[i]=2;
else if(a[i]=='G') s[i]=3;
solve(m,n);
}
return 0;
}

bzoj 3864: Hero meet devil的更多相关文章

  1. bzoj 3864: Hero meet devil [dp套dp]

    3864: Hero meet devil 题意: 给你一个只由AGCT组成的字符串S (|S| ≤ 15),对于每个0 ≤ .. ≤ |S|,问 有多少个只由AGCT组成的长度为m(1 ≤ m ≤ ...

  2. BZOJ 3864 Hero meet devil 超详细超好懂题解

    题目链接 BZOJ 3864 题意简述 设字符集为ATCG,给出一个长为\(n(n \le 15)\)的字符串\(A\),问有多少长度为\(m(m \le 1000)\)的字符串\(B\)与\(A\) ...

  3. bzoj 3864: Hero meet devil(dp套dp)

    题面 给你一个只由\(AGCT\)组成的字符串\(S (|S| ≤ 15)\),对于每个\(0 ≤ .. ≤ |S|\),问 有多少个只由\(AGCT\)组成的长度为\(m(1 ≤ m ≤ 1000) ...

  4. BZOJ 3864 Hero meet devil (状压DP)

    最近写状压写的有点多,什么LIS,LCSLIS,LCSLIS,LCS全都用状压写了-这道题就是一道状压LCSLCSLCS 题意 给出一个长度为n(n<=15)n(n<=15)n(n< ...

  5. BZOJ 3864 Hero Meets Devil

    题目大意 给定一个由AGCT组成的串\(t\), 求对于所有的\(L \in [1, |t|]\), 有多少个由AGCT组成的串\(s\)满足\(LCS(s, t) = L\). Solution 传 ...

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

  7. bzoj千题计划241:bzoj3864: Hero meet devil

    http://www.lydsy.com/JudgeOnline/problem.php?id=3864 题意: 给你一个DNA序列,求有多少个长度为m的DNA序列和给定序列的LCS为0,1,2... ...

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

  9. bzoj3864: Hero meet devil

    Description There is an old country and the king fell in love with a devil. The devil always asks th ...

随机推荐

  1. MVC3使用Area解耦项目

    源代码 1.增加AreasChildRegistration类,类继承PortableAreaRegistration 2.增加引用MvcContrib 3.主项目中Area文件夹下增加Web.con ...

  2. STL之set&multiset使用简介

    关于set,必须说明的是set关联式容器.set作为一个容器也是用来存储同一数据类型的数据类型,并且能从一个数据集合中取出数据,在set中每个元素的值都唯一,而且系统能根据元素的值自动进行排序.应该注 ...

  3. MySQL事物相关学习

    总结下最近对MySQL数据库的认识 Q:在手动开启事物后,commit失败是否需要显示的rollback? A:在网上查了不少资料,没有查到明确的答案.问了身边的朋友,朋友也不太了解,不过均表示显示的 ...

  4. LeetCode(一)

    Q&A ONE Given an array of integers, return indices of the two numbers such that they add up to a ...

  5. ThreadPoolExecutor源码解析

    LZ目前正在做一个批量生成报表的系统,需要定时批量生成多张报表,便考虑使用线程池来完成.JDK自带的Executors工具类只提供创建固定线程和可伸展但无上限的两个静态方法,并不能满足LZ想自定制线程 ...

  6. Nginx日志管理配置

    1.创建日志目录 nginx 的默认日志目录所在硬盘空间可能比较小,所以根据硬盘的空间状况创建日志目录 例如:mkdir /backup/nginx_logs 2.修改nginx配置文件 配置 ngi ...

  7. 一文看懂Kafka消息格式的演变

    摘要 对于一个成熟的消息中间件而言,消息格式不仅关系到功能维度的扩展,还牵涉到性能维度的优化.随着Kafka的迅猛发展,其消息格式也在不断的升级改进,从0.8.x版本开始到现在的1.1.x版本,Kaf ...

  8. DP———3.最长上升子序列的和

    Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. May ...

  9. Python实现队列

    队列的数据结构的主要结构:一个结点类和两个方法:出队列和进队列 class Node(object): def __init__(self,val): self.val = val self.next ...

  10. canvas2D 基础知识 浅析

    1.canvas HTML5给出的一个可以展示绘图内容的标签 使用领域: (推荐网站:threejs.org) 1. 游戏   2. 可视化数据  3. Banner广告  4. 多媒体 (1)在 c ...