DNA sequence

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

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
思路:迭代加深搜索。含义:在不知道迭代深度的前提下,依次探索每次的搜索深度。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN=;
struct Node{
char s[MAXN];
int len,top;
}DNA[MAXN];
int n;
char buf[]={'A','C','G','T'};
bool dfs(int l,int limit)
{
int remain=;
for(int i=;i<n;i++)
{
if(DNA[i].len-DNA[i].top>remain)
{
remain=DNA[i].len-DNA[i].top;
}
}
if(remain==) return true;
if(remain+l>limit) return false; //重要剪枝一 for(int i=;i<;i++)
{
bool tag=false;
int vis[MAXN]={};
for(int j=;j<n;j++)
{
if(buf[i]==DNA[j].s[DNA[j].top])
{
vis[j]=;
DNA[j].top++;
tag=true;
}
}
if(!tag) continue;//重要剪枝二
if(dfs(l+,limit))
{
return true;
}
for(int j=;j<n;j++)
{
if(vis[j])
{
DNA[j].top--;
}
}
}
return false;
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
int limit=;
for(int i=;i<n;i++)
{
scanf("%s",DNA[i].s);
DNA[i].len=strlen(DNA[i].s);
DNA[i].top=;
limit=max(limit,DNA[i].len);
}
while(!dfs(,limit))
{
for(int i=;i<n;i++)
{
DNA[i].top=;
}
limit++;
}
printf("%d\n",limit);
}
return ;
}

HDU1560(迭代加深搜索)的更多相关文章

  1. POJ1129Channel Allocation[迭代加深搜索 四色定理]

    Channel Allocation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14601   Accepted: 74 ...

  2. BZOJ1085: [SCOI2005]骑士精神 [迭代加深搜索 IDA*]

    1085: [SCOI2005]骑士精神 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1800  Solved: 984[Submit][Statu ...

  3. 迭代加深搜索 POJ 1129 Channel Allocation

    POJ 1129 Channel Allocation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14191   Acc ...

  4. 迭代加深搜索 codevs 2541 幂运算

    codevs 2541 幂运算  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题目描述 Description 从m开始,我们只需要6次运算就可以计算出 ...

  5. HDU 1560 DNA sequence (IDA* 迭代加深 搜索)

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1560 BFS题解:http://www.cnblogs.com/crazyapple/p/321810 ...

  6. UVA 529 - Addition Chains,迭代加深搜索+剪枝

    Description An addition chain for n is an integer sequence  with the following four properties: a0 = ...

  7. hdu 1560 DNA sequence(迭代加深搜索)

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

  8. 迭代加深搜索 C++解题报告 :[SCOI2005]骑士精神

    题目 此题根据题目可知是迭代加深搜索. 首先应该枚举空格的位置,让空格像一个马一样移动. 但迭代加深搜索之后时间复杂度还是非常的高,根本过不了题. 感觉也想不出什么减枝,于是便要用到了乐观估计函数(O ...

  9. C++解题报告 : 迭代加深搜索之 ZOJ 1937 Addition Chains

    此题不难,主要思路便是IDDFS(迭代加深搜索),关键在于优化. 一个IDDFS的简单介绍,没有了解的同学可以看看: https://www.cnblogs.com/MisakaMKT/article ...

随机推荐

  1. leetcode刷题1:两数之和two_sum

    题目:(难度:Easy) 给定一个整数数组和一个目标值,找出数组中和为目标值的两个数. 你可以假设每个输入只对应一种答案,且同样的元素不能被重复利用. 示例: 给定 nums = [2, 7, 11, ...

  2. Kubernetes Rook

    Rook Rook 是一个开源的cloud-native storage编排, 提供平台和框架:为各种存储解决方案提供平台.框架和支持,以便与云原生环境本地集成. Rook 将存储软件转变为自我管理. ...

  3. Yii和ThinkPHP对比杂谈

    关于ThinkPHP(以下简称TP)和Yii Framework(以下简称Yii)的背景.作者和速度方面就不涉及了.因为速度是一个很复杂的问题,牵扯的因素很多.我不得不承认ThinkPHP是 一个是国 ...

  4. Qt QT的IO流 QT输入输出

    1. QFile QDataStream 读写文件  二进制读写文件 #include <QApplication> #include <QtGui> #include < ...

  5. 运行php的时候出现计算机中丢失 MSVCR110.dll怎么解决

    运行php的时候出现计算机中丢失 MSVCR110.dll怎么解决 一.总结 一句话总结:因为现在php所有的 5.5 环境都是基于 vc11 的编译脚本下生成的,所以在 windows 下你得安装相 ...

  6. jstl: <c:url> 标签

    这个标签主要是用来重写 URL 地址.它的使用格式如下所示:<c:url value=”value” [context=”context”] [var=”varName”] [scope=”pa ...

  7. Lucene.Net 优化索引生成,即搜索显示优化

    最近发现站内搜索引擎响应速度很慢,因为刚来公司之前技术员跑了源码什么的都没留下.只好自己手动破解源代码dll查找问题所在! 这个问题代码就暂时不贴了这里只写思路 原逻辑:经过整体分析后发现之前是使用 ...

  8. "阿拉伯""伊斯兰""穆斯林"三个概念怎么分?

    伊斯兰.阿拉伯.穆斯林这三个概念到底有什么不同?要言君将用五分钟给您概述这三个概念,并厘清其边界,说明其交集,帮您迅速构建"阿拉伯.伊斯兰.穆斯林"知识结构概图.相信您得沉思一下费 ...

  9. 如何在windows上部署war包到tomcat服务器

    一. 什么是war包 WAR(Web Archive file)网络应用程序文件,是与平台无关的文件格式,它允许将很多文件组合成一个压缩文件.war专用在web方面,一个war包可以理解为一个web项 ...

  10. db2还原离线备份文件报错SQL2071N 提示“访问共享库出现错误”解决

    db2 buffers buffer 提示报错: SQL2071N  An error occurred while accessing the shared library  “/home/db2a ...