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 ...
随机推荐
- selenium初识(二)——之webdriver API
配置完的环境之后,我们先来写一个小脚本: # __Author__:"Jim_xie" from selenium import webdriver from time impor ...
- 3dMax,Maya与FBX
3DMax下载地址(包含安装教程与注册方法):http://www.3d66.com/popsoft_1.html 3DMax已经自带导出为fbx格式的功能,所以无需安装fbx插件 Maya下载地址( ...
- (原)Unreal渲染模块 源码和实例分析说明
@author:白袍小道 说明 1.由于小道就三境武夫而已,而UE渲染部分不仅管理挺大,而且牵扯技术和内容驳杂,所以才有这篇梳理. 2.尽量会按书籍和资料,源码,小模块的调试和搬山(就是敲键盘)..等 ...
- lo口环路问题分析
流程如下,collecter抓取网卡lo和wlan0数据,其中lo口无数据,wlan0是笔记本上网网口,然后按自定义协议把数据包通过lo口发给后端dispatch进行分发! 这种模式下,抓包程序每经过 ...
- EasyUi DataGrid 请求Url两次问题
easyui datagrid 1.4 当total为0时,请求两次url问题 框架问题:需要在easyui文件后加修补补丁 /** * The Patch for jQuery EasyUI 1.4 ...
- rownum浅谈(一)
只要做web开发,几乎没有不需要分页查询的,在oracle中,rownum就是用来进行处理分页的. 1.rownum是oracle对结果集返回的一个伪列,也就是说是先查询完结果之后再加上的一个虚列,相 ...
- 团队项目-第二次Scrum 会议
时间:10.24 时长:30分钟 地点:线上 工作情况 团队成员 已完成任务 待完成任务 解小锐 学习官方样例 根据初步讨论结果编写初步的api文档 陈鑫 学习cocos creator基本使用 采用 ...
- Pandas根据条件赋值
我们有以下判断条件,我们想要更改B中的数, 而更改的位置是取决于 A 的. 对于A大于4的位置. 更改B在相应位置上的数为0. df.B[df.A>4] = 0
- Rational Rose 使用技巧
1.浏览区 2.菜单项 其中Format选项中: 决定各项是否显示,也可以通过右击-option选择 3.常用快捷键: F1:任何时候都可以按F1获得相关帮助,把鼠标放在某条菜单上按F1可以获得这条菜 ...
- redis各种数据结构使用场景
一.redis 数据结构使用场景 原来看过 redisbook 这本书,对 redis 的基本功能都已经熟悉了,从上周开始看 redis 的源码.目前目标是吃透 redis 的数据结构.我们都知道,在 ...