HDU 4899 Hero meet devil(状压DP)(2014 Multi-University Training Contest 4)
After the ring has been destroyed, the devil doesn't feel angry, and she is attracted by z*p's wisdom and handsomeness. So she wants to find z*p out.
But what she only knows is one part of z*p's DNA sequence S leaving on the broken ring.
Let us denote one man's DNA sequence as a string consist of letters from ACGT. The similarity of two string S and T is the maximum common subsequence of them, denote by LCS(S,T).
After some days, the devil finds that. The kingdom's people's DNA sequence is pairwise different, and each is of length m. And there are 4^m people in the kingdom.
Then the devil wants to know, for each 0 <= i <= |S|, how many people in this kingdom having DNA sequence T such that LCS(S,T) = i.
You only to tell her the result modulo 10^9+7.
For each test case, the first line contains a string S. the second line contains an integer m.
T<=5
|S|<=15. m<= 1000.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int MAXN = ;
const int MOD = 1e9 + ; char dic[] = "ACTG";
int add[ << ][];
int dp[][ << ];
int pre[MAXN], lcs[MAXN], ans[MAXN];
char s[MAXN];
int T, n, m; inline void update_add(int &a, int b) {
a += b;
if(a >= MOD) a -= MOD;
} void init() {
for(int state = ; state < ( << n); ++state) {
pre[] = ;
for(int i = ; i <= n; ++i) pre[i] = pre[i - ] + ((state >> (i - )) & );
for(int k = ; k < ; ++k) {
for(int i = ; i <= n; ++i) {
if(s[i] == dic[k]) lcs[i] = pre[i - ] + ;
else lcs[i] = max(lcs[i - ], pre[i]);
}
int &t = add[state][k] = ;
for(int i = ; i <= n; ++i)
t |= ((lcs[i] != lcs[i - ]) << (i - ));
}
}
} void solve() {
int *now = dp[], *next = dp[];
memset(next, , ( << n) * sizeof(int));
next[] = ;
for(int _ = ; _ < m; ++_) {
swap(now, next);
memset(next, , ( << n) * sizeof(int));
for(int state = ; state < ( << n); ++state) if(now[state])
for(int k = ; k < ; ++k)
update_add(next[add[state][k]], now[state]);
}
memset(ans, , sizeof(ans));
for(int state = ; state < ( << n); ++state) {
update_add(ans[__builtin_popcount(state)], next[state]);
}
for(int i = ; i <= n; ++i)
printf("%d\n", ans[i]);
} int main() {
scanf("%d", &T);
while(T--) {
scanf("%s%d", s + , &m);
n = strlen(s + );
init();
solve();
}
}
HDU 4899 Hero meet devil(状压DP)(2014 Multi-University Training Contest 4)的更多相关文章
- HDU 4899 Hero meet devil (状压DP, DP预处理)
题意:给你一个基因序列s(只有A,T,C,G四个字符,假设长度为n),问长度为m的基因序列s1中与给定的基因序列LCS是0,1......n的有多少个? 思路:最直接的方法是暴力枚举长度为m的串,然后 ...
- BZOJ 3864 Hero meet devil (状压DP)
最近写状压写的有点多,什么LIS,LCSLIS,LCSLIS,LCS全都用状压写了-这道题就是一道状压LCSLCSLCS 题意 给出一个长度为n(n<=15)n(n<=15)n(n< ...
- hdu 4899 Hero meet devil
传送阵:http://acm.hdu.edu.cn/showproblem.php?pid=4899 题目大意:给定一个DNA序列,求有多少长度为m的序列与该序列的最长公共子序列长度为0,1...|S ...
- HDU 6149 Valley Numer II 状压DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6149 题意:中文题目 解法:状压DP,dp[i][j]代表前i个低点,当前高点状态为j的方案数,然后枚 ...
- HDU 5434 Peace small elephant 状压dp+矩阵快速幂
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5434 Peace small elephant Accepts: 38 Submissions: ...
- HDU 1074 Doing Homework(状压DP)
第一次写博客ORZ…… http://acm.split.hdu.edu.cn/showproblem.php?pid=1074 http://acm.hdu.edu.cn/showproblem.p ...
- HDU 4906 Our happy ending (状压DP)
HDU 4906 Our happy ending pid=4906" style="">题目链接 题意:给定n个数字,每一个数字能够是0-l,要选当中一些数字.然 ...
- HDU 1074 Doing Homework (状压dp)
题意:给你N(<=15)个作业,每个作业有最晚提交时间与需要做的时间,每次只能做一个作业,每个作业超出最晚提交时间一天扣一分 求出扣的最小分数,并输出做作业的顺序.如果有多个最小分数一样的话,则 ...
- HDU 4568 Hunter 最短路+状压DP
题意:给一个n*m的格子,格子中有一些数,如果是正整数则为到此格子的花费,如果为-1表示此格子不可到,现在给k个宝藏的地点(k<=13),求一个人从边界外一点进入整个棋盘,然后拿走所有能拿走的宝 ...
随机推荐
- 关于Memo或者Edit之类控件, 直接设置Text无法撤销的解决方案
昨天看到群里有人问使用Memo1.Text := '11111';来设置内容的代码无法使用Memo1.Undo的方式来撤销 测试了一下果然如此, 跟踪了VCL代码, 发现Text := '11111' ...
- C# DateTime类型和时间戳 互相转换
/// <summary> /// 时间戳转为C#格式时间 /// </summary> /// <param name=”timeStamp”></para ...
- Lazarus for Raspbian安装
春节前看到树莓派 2代开始销售,第一时间在淘宝下单购买,无奈春节期间放假,要到3月份才可能收到,只能用QEMU模拟器先熟悉树莓系统.对从turbo Pascal开始的人来讲,如果能在树莓系统使用Pas ...
- python装饰器方法
前几天向几位新同事介绍项目,被问起了@login_required的实现,我说这是django框架提供的装饰器方法,验证用户是否登录,只要这样用就行了,因为自己不熟,并没有做过多解释. 今天查看dja ...
- ArcGIS API for Silverlight实现地图测距功能
原文:ArcGIS API for Silverlight实现地图测距功能 问题:如何实现地图测距功能? 地图工具栏 <Grid x:Name="gToolMenu" Hei ...
- EChars学习-2
上海的echars学习 <html> <head> <meta charset="utf-8"> <meta http-equiv=&qu ...
- ar1020 驱动移植 无效
移植ar1020的spi驱动.驱动移植过来后,在原来的板子上都能够正常运行,而在新的板子却没有效果. 最后查看新旧板子的AR1020的电路,发现M2引脚连接不同.M2高电平连接的touch是5线的接口 ...
- css中各种居中的奇技淫巧总结
css中各种居中的奇技淫巧总结 第一种,在固定布局中比较常用的技巧设置container的margin:0 auto: 第二种(从布局中入手) css .outer{ height:200 ...
- opencv3.0+VS2015+64位win7配置
首先,我们把所有用到的工具下载下来 VS2015 看这里,http://news.mydrivers.com/1/439/439398.htm,我下载的是专业版. OPENCV3.0 ...
- iOS 并发编程指南
iOS Concurrency Programming Guide iOS 和 Mac OS 传统的并发编程模型是线程,不过线程模型伸缩性不强,而且编写正确的线程代码也不容易.Mac OS 和 iOS ...