DNA sequence

Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2427    Accepted Submission(s): 1198

Problem Description

The twenty-first century is a biology-technology developing century. We know that a gene is made of DNA. The nucleotide bases from which DNA is built are A(adenine), C(cytosine), G(guanine), and T(thymine). Finding the longest common subsequence between DNA/Protein sequences is one of the basic problems in modern computational molecular biology. But this problem is a little different. Given several DNA sequences, you are asked to make a shortest sequence from them so that each of the given sequence is the subsequence of it.

For example, given "ACGT","ATGC","CGTT" and "CAGT", you can make a sequence in the following way. It is the shortest but may be not the only one.

 

Input

The first line is the test case number t. Then t test cases follow. In each case, the first line is an integer n ( 1<=n<=8 ) represents number of the DNA sequences. The following k lines contain the k sequences, one per line. Assuming that the length of any sequence is between 1 and 5.
 

Output

For each test case, print a line containing the length of the shortest sequence that can be made from these sequences.
 

Sample Input

1
4
ACGT
ATGC
CGTT
CAGT
 

Sample Output

8
 

Author

LL

对公共串的每一位进行搜索,并使用IDA*剪枝

 //2017-03-07
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; string DNA[];
char ch[] = {'A', 'T', 'C', 'G'};
int deep, n, pos[];//pos[i]表示第i个DNA串匹配到了pos[i]位
bool ok; int Astar()//估价函数,返回当前状态最少还需要多少位
{
int h = ;
for(int i = ; i < n; i++)
if(h < DNA[i].length()-pos[i])
h = DNA[i].length()-pos[i];
return h;
} void IDAstar(int step)//枚举所求串每一位的字符,step表示所求串当前处理到哪一位。
{
if(ok)return;
int h = Astar();
if(step + h > deep)return;//剪枝
if(h == ){//h为0表示短串全部处理完
ok = true;
return;
}
for(int i = ; i < ; i++)
{
int tmp[];
for(int j = ; j < n; j++)tmp[j] = pos[j];
bool fg = false;
for(int j = ; j < n; j++)
{
if(DNA[j][pos[j]] == ch[i]){
fg = true;//表示所求串第step为可以是ch[i]
pos[j]++;
}
}
if(fg){
IDAstar(step+);
}
for(int j = ; j < n; j++)pos[j] = tmp[j];
}
} int main()
{
int T;
cin>>T;
while(T--)
{
cin>>n;
deep = ;
for(int i = ; i < n; i++)
{
cin>>DNA[i];
if(DNA[i].length() > deep)deep = DNA[i].length();
}
ok = false;
while(!ok)
{
memset(pos, , sizeof(pos));
IDAstar();
deep++;
}
cout<<deep-<<endl;
} return ;
}

HDU1560(KB2-E IDA星)的更多相关文章

  1. HDU1560 DNA sequence —— IDA*算法

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1560 DNA sequence Time Limit: 15000/5000 MS (Java/Oth ...

  2. HDU1560 DNA sequence IDA* + 强力剪枝 [kuangbin带你飞]专题二

    题意:给定一些DNA序列,求一个最短序列能够包含所有序列. 思路:记录第i个序列已经被匹配的长度p[i],以及第i序列的原始长度len[i].则有两个剪枝: 剪枝1:直接取最长待匹配长度.1900ms ...

  3. Bzoj3041 水叮当的舞步

    Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 132  Solved: 75 Description 水叮当得到了一块五颜六色的格子形地毯作为生日礼物 ...

  4. POJ4007 Flood-it!

      Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 337   Accepted: 123 Description Flood ...

  5. HDU1560 DNA sequence(IDA*)题解

    DNA sequence Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) To ...

  6. Hdu1560 DNA sequence(IDA*) 2017-01-20 18:53 50人阅读 评论(0) 收藏

    DNA sequence Time Limit : 15000/5000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total ...

  7. BNUOJ34977夜空中最亮的星(数学,向量的应用)

    夜空中最亮的星 Time Limit: 2000ms Memory Limit: 65536KB 64-bit integer IO format: %lld      Java class name ...

  8. 星浩资本快速发展引擎:IT就是生产力

    星浩资本成立于2010年,是一家涵盖私募基金.开发管理.商业与现代服务业三大业务范围的综合性管理公司,专注于投资中国首创.高成长性.高回报率的创新型城市综合体. 年轻的星浩资本在商业投资上有其独到的商 ...

  9. 读过MBA的CEO更自私?《哈佛商业评论》2016年第12期。4星

    老牌管理杂志.每期都值得精度.本期我还是给4星. 以下是本书中的一些内容的摘抄: 1:他们发现在Airbnb上,如果客人姓名听起来像黑人,那么比名字像白人的客人的接受率会低16%.#45 2:对立组织 ...

随机推荐

  1. myeclipse注册码生成

    import java.io.*; /** * <一句话功能简述> * <功能详细描述> * * @author 程松 * @date 2013-11-8上午8:50:34 * ...

  2. ionic的基础学习(第一篇)

    1.ioinc的头部与底部 1.Header 固定在屏幕的顶端的组件,可包含标题,左右的功能按钮.(提供很多颜色的样式,及调用不同的样式名,亦可自定义) bar-light,bar-stable,ba ...

  3. docker安装指定版本TAG的镜像

    在docker中安装镜像,一般过程是,docker search 软件名称. 本文以tomcat为例,讲解下载指定版本TAG的tomcat. 搜索tomcat镜像 $ sudo docker sear ...

  4. chromedriver与google版本的对应

    解决chromedriver与chrome版本不兼容的问题 附chromedriver下载地址http://npm.taobao.org/mirrors/chromedriver/ 以下是对应的chr ...

  5. Monkey学习笔记<三>:Monkey脚本编写

    我们都知道Monkey是向手机发送伪随机事件流,但是有时候我们需要实现特定的事件流,这时候我们可以用Monkey脚本来实现. 通过对monkey的API研究发现,我们可以通过-f这个参数来实现monk ...

  6. eclip 重写从父类继承的方法的快捷操作

    转载自http://blog.sina.com.cn/s/blog_53d599430101phlo.html     一.在代码中单击鼠标右键,在弹出的快捷菜单中选择“源代码(Source)”-&g ...

  7. hive多表联合查询(GroupLens->Users,Movies,Ratings表)

    hive (UserMovieRating)> create table if not exists Users(                      > UserID int co ...

  8. Javascript中Date对象的格式化

    很多语言中都带有日期的格式化函数,而Javascript中却没有提供类似的方法.之前从某位前人的帖子中发现了下面的代码,感觉非常简洁,存留备用. /** * 时间对象的格式化; */ Date.pro ...

  9. 按照Right-BICEP要求对实验二进行测试

    我的代码实现的功能很简单,在最基本的功能上,包括有无括号(0/1),有无负数(0/1),有无乘除法(0/1)验证程序的正确性,测试用例为8个,2^3个,也就覆盖了所有的代码路径. 测试计划: 基本功能 ...

  10. C#的Equals不区分大小写

    代码:System.Windows.Forms.MessageBox.Show("abc".Equals("ABC", StringComparison.Inv ...