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. Escape From The Earth 逃离地球

    1.对Tags进行管理 设置一个全局的类,类似如下: public class Tags:MonoBehaviour{ public const string player="Player& ...

  2. 爬虫:Scrapy15 - 调试(Debugging)Spiders

    考虑下面的 spider: import scrapy from myproject.items import MyItem class MySpider(scrapy.Spider): name = ...

  3. java.net.SocketException: recvfrom failed: EBADF (Bad file descriptor)

    1. 问题说明: 与服务器之间进行socket通信的时候,客户端关闭socket之后,会抛出一个IOException,异常信息如下: java.net.SocketException: recvfr ...

  4. SQL 唯一标识 写法

    创建唯一标识的方法~16位唯一标识 SELECT LTRIM(STR(CONVERT(varchar(100), GETDATE(), 112)))+right(cast(power(10,6) as ...

  5. 命令__cp、scp(Secure Copy)

    cp命令:区别:硬链接原文件&链接文件公用一个inode号,说明他们是同一个文件,而软链接原文件&链接文件拥有不同的inode号,表明他们是两个不同的文件: 在文件属性上软链接明确写出 ...

  6. 性能优化-FSL(Force Synchronous Layout)强制同步布局

    通过chrome的Perfermance工具记录程序性能,切换到帧模式,点开其中一帧,看详情,中间为紫色的区块代表Layout,右上角带有红色三角的为警告,是chrome告知的强制同步布局,即FSL. ...

  7. EAR、JAR、WAR(IT)

    EAR文件包括整个项目,内含多个ejb module(jar文件)和web module(war文件)   JAR.WAR.EAR.在文件结构上,三者并没有什么不同,它们都采用zip或jar档案文件压 ...

  8. CF10D LCIS (动态规划)

    题目链接 Solution 动态规划. 令 \(f_{i,j}\) 表示 \(a\) 数组前 \(i\) 个和 \(b\) 数组前 \(j\) 所得的最长的 LCIS . 转移很好想: \(a_i!= ...

  9. poj1679 次最小生成树 kruskal(暴力枚举)

    Description Given a connected undirected graph, tell if its minimum spanning tree is unique. Definit ...

  10. 模拟Windows系统“回收站”

    HTML: <!DOCTYPE html><html> <head> <meta http-equiv="content-type" co ...