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中的安全模型(沙箱机制)

    java中的安全模型(沙箱机制) java安全沙箱(一)之ClassLoader双亲委派机制 java安全沙箱(二)之.class文件检验器 java安全沙箱(三)之内置于Java虚拟机(及语言)的安 ...

  2. 消息中间件(一)MQ详解及四大MQ比较

    一.消息中间件相关知识 1.概述 消息队列已经逐渐成为企业IT系统内部通信的核心手段.它具有低耦合.可靠投递.广播.流量控制.最终一致性等一系列功能,成为异步RPC的主要手段之一.当今市面上有很多主流 ...

  3. day 44 django 学习入门

    前情提要: 终于学到了Django  ...古川小姐姐好流b .....7天学完.....脑壳疼..为了出了这个小火箭.. 详细参考官网. https://www.django.cn/ 中文网站 一: ...

  4. day 32 css后续补充以及js 简单入门

    前情提要: 利用html 和css ,js 模拟小米的官网(待做) 一:第一个sj利子 <!DOCTYPE html> <html lang="en"> & ...

  5. OpenCV --- 修改图像的对比度、亮度 、RGB转Gray图像、修改图像的尺寸

    #include <opencv2/core.hpp> #include <opencv2/imgcodecs.hpp> #include <opencv2/highgu ...

  6. TapTap推广统计逻辑

    当我们在Taptap上访问某款游戏时,比如https://www.taptap.com/app/34762,taptap会记录下这次访问,它是怎么做的呢. 首先,用记事本打开这个网址,在head部分看 ...

  7. Liunx安装Git

    环境:CentOS 6.5 min 安装git yum -y install gcc curl curl-devel zlib-devel openssl-devel perl cpio expat- ...

  8. web测试总结—用户体验

    一.什么是用户体验 用户体验,英文叫做user experience,缩写为UE,或者UX.一个较常见的定义是“指用户访问一个网站或者使用一个产品时的全部体验.他们的印象和感觉,是否成功,是否享受,是 ...

  9. SPSS学习系列之SPSS Modeler怎么修改默认的内存大小(图文详解)

    不多说,直接上干货! 问题来源: 如果你的电脑内存配置比较低的话,会随着数据量增加(尤其是大数据),带不起的情况很有可能发生,会出现一些内存报错... ... 解决办法: 打开“工具”,在modele ...

  10. Python -- Gui编程 -- Qt库的使用 -- 配置资源文件

    1.源文件(qtRes.py) import sys from PyQt4 import QtCore, QtGui, uic class MyDialog(QtGui.QDialog): def _ ...