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. ACM训练小结-2018年6月15日

    今天题目情况如下:A题:给出若干条边的边长,问这些边按顺序能否组成一个凸多边形,并求出这个多边形的最小包含圆.答题情况:无思路.正解(某种):第一问很简单.对第二问,如果R大于可行的最小R,那么按照放 ...

  2. uboot无法引导uImage错误及其解决方法

    先编译友善提供的linux内核: make ARCH=arm mini2440_defconfigmake CROSS_COMPILE=arm-linux- uImage 在arch/arm/boot ...

  3. js学习笔记1(变量、作用域、内存)

    写在前面,舍弃叽叽歪歪,只做学习笔记,认真踏实. 学习书籍:javascript高级程序设计3版. 章节4.1 基本类型和引用类型 1.基本类型在内存中占据固定大小的空间,所以保存在栈内存中. 2.从 ...

  4. JAVA基础补漏--字符串

    字符串常量池 String a="abc"; String b="abc"; char[] str = {"a","b" ...

  5. Maven webapp index.jsp报错

    javax.servlet javax.servlet-api 3.1.0

  6. js简单工厂

    我以计算器为例写一个简单工厂模式,只完成加减乘除4个计算功能,考虑到其他功能方便日后扩展,遵循开放-封闭原则. 简单工厂类图: 先看一下C#的简单工厂是如何实现的: 定义抽象类Operation,加减 ...

  7. Mac的搜狗输入法和QQ输入法加入⌘⌥⌃⇧自定义短语

    搜狗输入法(Mac):http://pinyin.sogou.com/mac/ 创建名为『搜狗输入法自定义短语.ini』的文本文件(建议用Sublime Text),内容如下,然后偏好设置的自定义短语 ...

  8. hzau 1207 Candies

    1207: Candies Time Limit: 2 Sec  Memory Limit: 1280 MBSubmit: 223  Solved: 31[Submit][Status][Web Bo ...

  9. c#将DataTable内容导出为CSV文件

    写了个类: class DataTableAndCSV { public static DataTable csvToDataTable(string file) { string strConn = ...

  10. Object.assign()与深拷贝(一)

    深拷贝与浅拷贝 所谓深拷贝与浅拷贝,是围绕引用类型变量的拷贝进行的讨论. 在ECMAScript中,变量分为基本类型和引用类型两种.其本质区别是不可变性,基本类型是不可变的,而引用类型是可变的. 所谓 ...