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. numpy模块之创建矩阵、矩阵运算

    本文参考给妹子讲python  https://zhuanlan.zhihu.com/p/34673397 NumPy是Numerical Python的简写,是高性能科学计算和数据分析的基础包,他是 ...

  2. python装饰器实现HTTP请求耗时和入参返回日志记录

    装饰器方法: 1 def decoArgs(server_name): 2 def deco(func): 3 def wrapper(view, request, *args, **kwargs): ...

  3. One 的使用(1)

    方法一:使用命令提示符 第一步:打开d盘  C:Users\dcf>d; 第二步:打开工作空间  D:\>Cd workspace 第三步:打开the one  D:\workspace& ...

  4. linux设置系统时间与时区以及设置bios时间同步系统时间

    有装过Linux系统的人,可能都会有这样的经历,就是该机器安装windows系统时,时间正确,但是安装了linux系统后,尽管时区选择正确,也会发现系统时间不对.这是由于安装系统时采用了UTC,那么什 ...

  5. 【P2514】工厂选址(贪心)

    看到题了不首先应该看看数据范围确定一下算法么,这个题的数据范围大约可以支持到O(nmlogm),所以肯定不是搜索什么的,DP貌似至少也要n^2m,所以可以想一些其他的.对于题目的输入,我们发现这些输入 ...

  6. Centos7 docker容器 搭建

    Dockerfile 文件如下: # # MAINTAINER Carson,C.J.Zeong <zcy@nicescale.com> # DOCKER-VERSION # # Dock ...

  7. 几招教会你解决网站出现DNS域名解析错误的困扰!

    DNS解析就是把你的域名解析成一个ip地址,服务商提供的dns解析就是能够将你的域名解析成相应ip地址的主机.这就是DNS域名解析. DNS解析出现错误,一般是我们把一个域名解析成一个错误的IP地址, ...

  8. Spring学习之xml配置Bean总结

    学习Spring时,我用的是Maven来管理jar包,先看看maven的pom.xml: pom.xml <project xmlns="http://maven.apache.org ...

  9. form组件的总结

    1.form组件(******) 局部钩子 全局钩子 ''' 实例化时: self.fields={ "username":"字段规则对象", "pa ...

  10. linux下如何查看某个软件 是否安装??? 安装路径在哪???

    <1>.在linux下如何判断是否已经安装某个软件? 我的系统是red hat 我用命令rpm查是否安装了某个软件(例如: matlab 与 fluent ),得到了如下的结果: 我用rp ...