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. 程序猿的日常——Java基础之clone、序列化、字符串、数组

    其实Java还有很多其他的基础知识,在日常工作技术撕逼中也是经常被讨论的问题. 深克隆与浅克隆 在Java中创建对象有两种方式: 一种是new操作符,它创建了一个新的对象,并把对应的各个字段初始化成默 ...

  2. Kafka运行环境优化实践

    Kafka高性能的特点及条件 Kafka是一个高吞吐量分布式消息中间件,并且提供了消息的持久化功能.其高可行有两个重要的特点: 利用了磁盘连续读写性能显著高于随机读写性能的特点 并发,将一个topic ...

  3. (原创)确保JAVA线程安全的4种常用方法

    在Java中可以有很多方法来保证线程安全,比如使用同步方法.同步块,使用原子类(atomic concurrent classes),实现并发锁,使用volatile关键字,使用不变类和线程安全类. ...

  4. 彻底弄懂css3的flex弹性盒模型

    由于在日常工作中使用css或者bootstrap的栅格系统已经能很好的满足业务需求,所以一直以来对css3的弹性布局不是很感冒. 近日有幸在一篇文章中领略了flex的魅力--简洁优雅.随试之. /*容 ...

  5. activiti插件安装-离线安装

    直接选择离线安装,在线因为网络问题,一直提示失败. 一.下载插件Activiti BPMN 2.0 designer 链接: https://pan.baidu.com/s/1gKBHZFnmNJx7 ...

  6. Ethereum White Paper

    https://github.com/ethereum/wiki/wiki/White-Paper White Paper EditNew Page James Ray edited this pag ...

  7. openerp QWeb

    1.web 模块 注意,OpenERP 模块中 web 部分用到的所有文件必须被放置在模块内的 static 文件夹里.这是强制性的,出于安全考虑. 事实上,我们创建的文件夹 CSS,JS 和 XML ...

  8. 线程安全单例最佳实践,C#中的Lazy是如何保证线程安全的

    在.NET 4.0之后,.NET Framework中提供了一种安全的延迟加载类型LazyLazy能够在多线程环境下,保证GetValue函数只执行一次,从而实现单例模式 在过去,实现单例模式我们通常 ...

  9. (转)MySQL 加锁处理分析

    MySQL 加锁处理分析 原文:http://hedengcheng.com/?p=771 1    背景    1 1.1    MVCC:Snapshot Read vs Current Read ...

  10. 【树】Unique Binary Search Trees II

    题目: Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. F ...