BZOJ3864 & HDU4899:Hero meet devil——题解
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——题解的更多相关文章
- 【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 ...
- HDU4899 Hero meet devil DP套DP
陈老师的题QwQ 原题链接 题目大意 有两个字符串\(S\)和\(T\)(都只能由'A','C','G','T'这四个字符组成),\(S\)已知\(T\)未知,还知道\(S\)的长度为\(m\).求满 ...
- hdu4899 Hero meet devil
题目链接 题意 给出一个长度字符串\(T\),其中只包含四种字符\((A,C,G,T)\),需要找一个字符串\(S\),使得\(S\)的长度为\(m\),问\(S\)和\(T\)的\(lcs\)为\( ...
- bzoj 3864: Hero meet devil [dp套dp]
3864: Hero meet devil 题意: 给你一个只由AGCT组成的字符串S (|S| ≤ 15),对于每个0 ≤ .. ≤ |S|,问 有多少个只由AGCT组成的长度为m(1 ≤ m ≤ ...
- bzoj3864: Hero meet devil
Description There is an old country and the king fell in love with a devil. The devil always asks th ...
- BZOJ3864: Hero meet devil(dp套dp)
Time Limit: 8 Sec Memory Limit: 128 MBSubmit: 397 Solved: 206[Submit][Status][Discuss] Description ...
- BZOJ 3864 Hero meet devil 超详细超好懂题解
题目链接 BZOJ 3864 题意简述 设字符集为ATCG,给出一个长为\(n(n \le 15)\)的字符串\(A\),问有多少长度为\(m(m \le 1000)\)的字符串\(B\)与\(A\) ...
- 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 ...
- bzoj千题计划241:bzoj3864: Hero meet devil
http://www.lydsy.com/JudgeOnline/problem.php?id=3864 题意: 给你一个DNA序列,求有多少个长度为m的DNA序列和给定序列的LCS为0,1,2... ...
随机推荐
- meta-data获取小结
android 开发中: 在AndroidManifest.xml中,<meta-data>元素可以作为子元素, 被包含在<activity>.<applicat ...
- 「日常训练」School Marks(Codeforces Round 301 Div.2 B)
题意与分析(CodeForces 540B) 题意大概是这样的,有一个考试鬼才能够随心所欲的控制自己的考试分数,但是有两个限制,第一总分不能超过一个数,不然就会被班里学生群嘲:第二分数的中位数(科目数 ...
- WEB中间件漏洞--IIS
1.iis安装 版本 一直下一步,选上iis安装 端口修改 网站目录 通过网站发布目录(发布目录任意),新建index.html页面,可以正常访问 2.iis6.0解析漏洞 (1)文件名解析 IIS在 ...
- Python数学运算入门把Python当作计算器
让我们尝试一些简单的 Python 命令.启动解释器,等待界面中的提示符,>>> (这应该花不了多少时间). 3.1.1. 数字 解释器就像一个简单的计算器一样:你可以在里面输入一个 ...
- 【WXS数据类型】Array
属性: 名称 值类型 说明 [Array].constructor [String] 返回值为“Array”,表示类型的结构字符串 [Array].length [Number] 返回数组长度 方法: ...
- 【转】: 《江湖X》开发笔谈 - 热更新框架
前言 大家好,我们这期继续借着我们工作室正在运营的在线游戏<江湖X>来谈一下热更新机制以及我们的理解和解决方案.这里先简单的介绍一下热更新的概念,熟悉这部分的朋友可以跳过,直接看我们的方案 ...
- 正式放弃Edge,重新拥抱Chrome
从Edge还叫斯巴达的时候我就开始用了,本来对浏览器的要求也没多高,能够打开多个选项卡,稳定,支持最新的规范就好了. 但是Edge真的是越来越让我失望了,卡死问题越来越多,崩溃越来越频繁,我也快奔溃了 ...
- ionic 日期插件学习
<ion-header> <ion-navbar> <ion-title> DateTime </ion-title> </ion-navbar& ...
- UVALive 3668 A Funny Stone Game(博弈)
Description The funny stone game is coming. There are n piles of stones, numbered with 0, 1, 2,..., ...
- 最短路径——Dijkstra(简易版)
简易之处:顶点无序号,只能默认手动输入0,1,2...(没有灵活性) #include <iostream> #include <cstdio> #include <cs ...