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. Bootstrap框架(二)

    day58 巨幕 这是一个轻量.灵活的组件,它能延伸至整个浏览器视口来展示网站上的关键内容. Hello, world! This is a simple hero unit, a simple ju ...

  2. 三,PHP缓存机制实现页面静态化

    页面静态化思路: 因为新闻这种信息对实时性要求不高,并且比较稳定,所以可以这样做:当地一个用户访问某条新闻后,我们使用ob缓存机制,将内容缓存到html页面.当下一次访问时候,直接访问html页面.这 ...

  3. HTML 5 使用 FileReader、FormData实现文件上传

    一.FileReader FileReader 对象允许Web应用程序异步读取存储在用户计算机中的文件(或缓冲区的原始数据),使用File或Blob对象指定要读取的文件或数据. 1.1 实例化 var ...

  4. Understanding Undefined Behavior

    "undefined behavior: behavior for which this International Standard imposes no requirements.&qu ...

  5. NOIP上机测试注意事项

    由于近期模拟题原地**次数较多,故写一篇警示文 1,头文件 1.1正式比赛中,反正我不敢用bits/stdc++.h. 1.2正式比赛中,建议打出以下十个库 #include<iostream& ...

  6. 【BZOJ1502】【NOI2005】月下柠檬树 simpson 积分

    特别提醒:eps至少要5e-6 首先我们来研究下平行光对投影的影响. 一个二维的图形,若它与光屏平行,那么不论平行光与光屏的夹角为多少,所得图形与原图形全等的(只是位置会有影响) 通过这么一分析,我们 ...

  7. Flowable BPMN 简单使用

    1.Flowable是什么? Flowable是一个使用Java编写的轻量级业务流程引擎.Flowable流程引擎可用于部署BPMN 2.0流程定义(用于定义流程的行业XML标准), 创建这些流程定义 ...

  8. (转)python学习笔记5--decimal

    原文:https://blog.csdn.net/lemonwyc/article/details/37583125 上一节提到了除了基本类型之外的decimal,这节就学习下.查看python3.4 ...

  9. 原生JavaScript的DOM操作方法总结

    什么是DOM? DOM即文档对象模型,Document Object Model.  是HTML和XML文档的编程接口.它提供了对文档的结构化的表述,并定义了一种方式可以使从程序中对该结构进行访问,从 ...

  10. Dubbo架构设计详解(转载)

    原文地址:http://shiyanjun.cn/archives/325.html Dubbo是Alibaba开源的分布式服务框架,它最大的特点是按照分层的方式来架构,使用这种方式可以使各个层之间解 ...