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. django项目中使用项目环境制作脚本 通过终端命令运行脚本文件

    在实际的django项目开发中,有时候需要制作一些脚本文件对项目数据进行处理,然后通过终端命令运行脚本. 完整的实现流程如下: 1.在一个应用目录下(app, 必须是在应用目录下,可以专门创建一个应用 ...

  2. 使用PhpSpreadsheet将Excel导入到MySQL数据库

    本文以导入学生成绩表为例,给大家讲解使用PhpSpreadsheet将Excel导入的MySQL数据库. 准备 首先我们需要准备一张MySQL表,表名t_student,表结构如下: CREATE T ...

  3. include与file_get_contents区别

    参考:http://www.cnblogs.com/bgwan/archive/2013/03/13/2957215.html 一,先来说file_get_contents         这个函数就 ...

  4. position:absolute元素 怎样居中

    <div style = 'height:20px;position:absolute;z-index:9999;top:0;left:0;right:0;margin:auto;'> & ...

  5. poj2506 Tiling

    http://poj.org/problem?id=2506 题目大意:用多少种方法可以用2*1或2*2瓦片来铺一个2*n的矩形? 这是一个2*17长方形的样品. 输入是一行行的序列,每一行包含一个整 ...

  6. php curl 伪造IP来源的实例代码

    来源:http://www.jb51.net/article/31694.htm curl 它不但可以模仿用户登录,还可以模仿用户IP地址哦,为伪造IP来源,本实例仅供参考哦 //伪造ip ; $i ...

  7. input 下拉框 的实践

    有一个需求  需要做一个input 框  点击出现列表 于是想到了  datalist控件 <input type="text" list="itemlist&qu ...

  8. 【css】——根据div个数显示不同的样式

    这里记录面试融众集团的一道题 Q:说可能有1~3个item显示在同一行,而item的个数不一定,如果1个,那这个item占宽100%,2个时每一个50%,3个时每一个33%,用纯CSS实现. A:先贴 ...

  9. javascript 实用工具函数

    整理日常开发中我们常常会使用到的一些工具函数. var utils = (function(){ var fay = {}; // 返回当前时间的毫秒数 fay.getTime = Date.now( ...

  10. 使用Pylint规范你的Python代码

    Pylint是一个Python代码风格的检查工具,功能上类似于pychecker,默认用PEP8作为代码风格标准,它所提供的功能包括:检查代码行的长度,检查变量命名是否符合规范,检查声明的接口是否被真 ...