https://www.lydsy.com/JudgeOnline/problem.php?id=3864

http://acm.hdu.edu.cn/showproblem.php?pid=4899

给你字符集为{A,T,G,C}的字符串,问有多少长度为m的字符串,满足其最长公共子序列长度为0,1……|S|。

太神啦,看巨佬博客吧:https://www.cnblogs.com/RabbitHu/p/BZOJ3864.html

#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int p=1e9+;
const int N=;
const int M=;
inline int read(){
int X=,w=;char ch=;
while(!isdigit(ch)){w|=ch=='-';ch=getchar();}
while(isdigit(ch))X=(X<<)+(X<<)+(ch^),ch=getchar();
return w?-X:X;
}
int s[N+];
int m,n,ans[N+],f[][<<N],last[<<N],trans[<<N][];
inline int readstring(){
int cnt=;char ch=;
while(ch<'A'||ch>'Z')ch=getchar();
while(ch>='A'&&ch<='Z'){
if(ch=='A')s[++cnt]=;if(ch=='T')s[++cnt]=;
if(ch=='G')s[++cnt]=;if(ch=='C')s[++cnt]=;
ch=getchar();
}
return cnt;
}
void init(){
static int d[N+],g[N+];
for(int i=;i< <<n;i++){
if(i)last[i]=last[i^(i&-i)]+;
for(int j=;j<n;j++)d[j+]=d[j]+(bool)(i&(<<j));
for(int k=;k<;k++){
for(int j=;j<=n;j++){
g[j]=max(g[j-],d[j]);
if(s[j]==k)g[j]=max(g[j],d[j-]+);
}
trans[i][k]=;
for(int j=;j<n;j++)
if(g[j+]-g[j])trans[i][k]|=<<j;
}
}
memset(ans,,sizeof(ans));
memset(f,,sizeof(f));
}
int main(){
int T=read();
while(T--){
n=readstring();m=read();
init();
f[][]=;int now=;
for(int i=;i<=m;i++){
memset(f[now],,sizeof(f[now]));
for(int j=;j< <<n;j++){
for(int k=;k<;k++){
(f[now][trans[j][k]]+=f[now^][j])%=p;
}
}
now^=;
}
for(int i=;i< <<n;i++)
(ans[last[i]]+=f[now^][i])%=p;
for(int i=;i<=n;i++)printf("%d\n",ans[i]);
}
return ;
}

BZOJ3864 & HDU4899:Hero meet devil——题解的更多相关文章

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

  2. HDU4899 Hero meet devil DP套DP

    陈老师的题QwQ 原题链接 题目大意 有两个字符串\(S\)和\(T\)(都只能由'A','C','G','T'这四个字符组成),\(S\)已知\(T\)未知,还知道\(S\)的长度为\(m\).求满 ...

  3. hdu4899 Hero meet devil

    题目链接 题意 给出一个长度字符串\(T\),其中只包含四种字符\((A,C,G,T)\),需要找一个字符串\(S\),使得\(S\)的长度为\(m\),问\(S\)和\(T\)的\(lcs\)为\( ...

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

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

  5. bzoj3864: Hero meet devil

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

  6. BZOJ3864: Hero meet devil(dp套dp)

    Time Limit: 8 Sec  Memory Limit: 128 MBSubmit: 397  Solved: 206[Submit][Status][Discuss] Description ...

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

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

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

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

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

随机推荐

  1. leetcode笔记--7 Find the Difference

    question: Given two strings s and t which consist of only lowercase letters. String t is generated b ...

  2. Selenium自动化测试第二天(下)

    如有任何学习问题,可以添加作者微信:lockingfree 目录 Selenium自动化测试基础 Selenium自动化测试第一天(上) Selenium自动化测试第一天(下) Selenium自动化 ...

  3. Linux命令应用大词典-第21章 LVM和RAID管理

    21.1 pvcreate:创建物理卷 21.2 pvscan:列出找到的物理卷 21.3 pvdisplay:显示物理卷的相关属性 21.4 vgcreate:创建卷组 21.5 vgscan:查找 ...

  4. mysql新手进阶02

    云想衣裳花想容,春风拂槛露华浓. 若非群玉山头见,会向瑶台月下逢. 现在有一教学管理系统,具体的关系模式如下: Student (no, name, sex, birthday, class) Tea ...

  5. 安迪的第一个字典 (Andy's First Dictionary,UVa10815)

    题目描述: #include<iostream> #include<string> #include<set> #include<sstream> us ...

  6. 【转】Unity 使用xLua遇到的坑

    在我们使用xLua作为Unity中lua集成的解决方案时,遇到了一个问题,就是当我们使用在lua中把UI中的某个控件绑定相应的事件(如按钮的onClick事件),xLua绑定这个事件是用委托实现的,具 ...

  7. Firefox-css-hack

    先记下:之后研究.试了一下,新版本FF-32.0效果不错,低版本还没测试. @-moz-document url-prefix() { .container { ... }}

  8. Python基础 之 tuple类-元组 和 dict类-字典

    tuple 元组 一.tuple 类的基本属性 1.元组,有序:元素不可被修改,不能被增加或者删除tuple类 tu = (111,22,33,44) 一般写元组的时候,推荐在最后加入,和类方法进行区 ...

  9. js经典试题之数据类型

    js经典试题之数据类型 1:输出"B" + "a" + + "B" + "a"的值: 答案:BaNaNa. 分析:因为+ ...

  10. Thunder团队第三周 - Scrum会议7

    Scrum会议7 小组名称:Thunder 项目名称:i阅app Scrum Master:胡佑蓉 工作照片: 邹双黛在照相,所以图片中没有该同学. 参会成员: 王航:http://www.cnblo ...