bzoj 3864: Hero meet devil
第一次写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的更多相关文章
- bzoj 3864: Hero meet devil [dp套dp]
3864: Hero meet devil 题意: 给你一个只由AGCT组成的字符串S (|S| ≤ 15),对于每个0 ≤ .. ≤ |S|,问 有多少个只由AGCT组成的长度为m(1 ≤ m ≤ ...
- BZOJ 3864 Hero meet devil 超详细超好懂题解
题目链接 BZOJ 3864 题意简述 设字符集为ATCG,给出一个长为\(n(n \le 15)\)的字符串\(A\),问有多少长度为\(m(m \le 1000)\)的字符串\(B\)与\(A\) ...
- bzoj 3864: Hero meet devil(dp套dp)
题面 给你一个只由\(AGCT\)组成的字符串\(S (|S| ≤ 15)\),对于每个\(0 ≤ .. ≤ |S|\),问 有多少个只由\(AGCT\)组成的长度为\(m(1 ≤ m ≤ 1000) ...
- BZOJ 3864 Hero meet devil (状压DP)
最近写状压写的有点多,什么LIS,LCSLIS,LCSLIS,LCS全都用状压写了-这道题就是一道状压LCSLCSLCS 题意 给出一个长度为n(n<=15)n(n<=15)n(n< ...
- BZOJ 3864 Hero Meets Devil
题目大意 给定一个由AGCT组成的串\(t\), 求对于所有的\(L \in [1, |t|]\), 有多少个由AGCT组成的串\(s\)满足\(LCS(s, t) = L\). Solution 传 ...
- 【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千题计划241:bzoj3864: Hero meet devil
http://www.lydsy.com/JudgeOnline/problem.php?id=3864 题意: 给你一个DNA序列,求有多少个长度为m的DNA序列和给定序列的LCS为0,1,2... ...
- 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 ...
- bzoj3864: Hero meet devil
Description There is an old country and the king fell in love with a devil. The devil always asks th ...
随机推荐
- HTML5新增属性学习笔记
1.form属性 表单内的从属元素,可以写在表单外部.可以通过指定元素的form属性来声明元素所属表单.form的属性值为表单的id. <form id="testForm" ...
- python学习笔记-参数带*
#!/usr/bin/python # -*- coding: utf-8 -*- def powersum (power,*args): #所有多余的参数都会作为一个元组存储在args中 s ...
- os--留
os.path.abspath(path) #返回绝对路径 绝对路径和文件路径的区别,绝对路径是当前在操作文本的路径,文件路径是当前文本的文件的路径 os.path.basename(path) ...
- win10 64位 C# 连接oracle 32位, 遇到的问题及解决
首次 本机电脑是win10系统 64位的:安装的oracle数据库也是64位的: 服务器端的oracle 是32位的: 第一次安装的pl/sql 也是64位的, 配置完 F:\app\ln_qi\p ...
- hadoop2.6.4【ubuntu】单机环境搭建 系列1
jdk安装 tar zxvf jdk mv jdk /usr/lib/jvm/java jdk环境变量配置 vim /etc/profile ``` export JAVA_HOME=/usr/lib ...
- SystemTap 用法
SystemTap需要内核符号表: http://ddebs.ubuntu.com/pool/main/l/linux/ 基本语法: next对应C中的return,中途返回: 今晚遗留了两个问题: ...
- IDEA 14注册码
用户: share密钥:78689-AFOCD-P3SDN-83DEC-BQ3UC-V6UK7用户: for密钥:13768-8VXX0-YL2BG-YBD88-2M3HN-CAOQ5用户: you密 ...
- [codeforces] 97B Superset || 平面分治
原题 给出一个平面的一些点,让你添加点,使得所有点对满足以下三个要求中的一个: 1.在一个水平面上 2.在一个竖直线上 3.以这两个点为对角的矩形内包含有其他点 输出一种可行解 因为只需要可行解,且只 ...
- Sublime Text 2 HTML代码缩进 美化HTML代码
关于代码格式的美化,之前在win下一直用“alignment”这个插件,它能实现一键对齐和缩进.最近使用mac版的sublime text 2,不知道是什么原因,这个插件疑似失效…… 这对有洁癖的完美 ...
- 【CF Round 429 B. Godsend】
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...