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. JDBC 工具类模板c3p0

    JDBC 工具类模板 package com.itheima.sh.utils; import com.mchange.v2.c3p0.ComboPooledDataSource; import ja ...

  2. 金山注入浏览器默认开启上网导航 www.uu114.cn

    金山注入浏览器默认开启上网导航 www.uu114.cn 今天突然发现我的电脑所有浏览器打开后,都会默认打开一个www.uu114.cn网站,chrome.firefox和IE都中招了.经过排查,发现 ...

  3. 解决replace格式替换后光标定位问题

    场景:格式化银行卡444格式 手机号344格式 身份证号684格式 校验数据格式,replace后光标定位错乱 或光标一直定位在最后 解决,只针对input,代码用的vue: 获取光标位置: getC ...

  4. Linux命令应用大词典-第38章 网络命令

    38.1 traceroute:显示跟踪到网络主机的路由数据包 38.2 mli-tool:查看.操纵网络接口状态 38.3 ifconfig:显示和配置网络接口 38.4 ifdown:关闭网络接口 ...

  5. Siki_Unity_1-3_Unity零基础入门_古迹探险

    1-3 Unity零基础入门 古迹探险 任务1/2:资料下载 链接:https://pan.baidu.com/s/1jHVymNk 密码:rbob 任务3:工程的创建和打开 Project:古迹探险 ...

  6. Python-3.6 安装pycrypto 2.6

    最近接触公司后台管理系统的开发,其中涉及到加密模块pycrypto. 重点来了!!!!敲黑板!!!! pycrypto在PyCharm中跟其他的模块不一样,pip install pycrypto安装 ...

  7. 【转】再谈PHP、Python与Ruby

    原文链接:http://www.nowamagic.net/librarys/veda/detail/2504 一句话总结 简单地总结: 假如你想帮他尽快找个活儿,赚到钱,推荐PHP. 假如你想让他成 ...

  8. 条款02:尽量以const,enum,inline替换#define

    一.概述 尽量少用预处理器——宏替换 二.细节 1. 关于宏替换之常量 旧版本:#define N 10; 新版本:const int n = 10; 比较:#define不被视为语言的一部分,记号名 ...

  9. 路由器如何设置上网(TP-LINK)

    最近宿舍公用的网络一直不太稳定,正赶上毕业季,本来就打算自己买一台自用的路由器,于是我从一个毕业的师姐手里15RMB收了一台路由器,师姐还给了我一根5m的网线和两根全新15m的,感觉光网线就赚翻了. ...

  10. UVALive - 6864 Strange Antennas 扫描线

    题目链接: http://acm.hust.edu.cn/vjudge/problem/87213 Strange Antennas Time Limit: 3000MS 题意 一个雷达能够辐射到的范 ...