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. php数组函数-array_pop()

    array_pop()函数删除数组中的最后一个元素(出栈). array_pop(array) array:必需.规定数组 返回值:返回数组的最后一个值.如果数组是空,或者不是一个数组,将返回NULL ...

  2. poj2528线段树解题报告,离散化+线段树

    题目网址:http://poj.org/problem?id=2528 题意: n(n<=10000)个人依次贴海报,给出每张海报所贴的范围li,ri(1<=li<=ri<=1 ...

  3. 【codevs1002】搭桥(prim)

    题目描述: 这是道题题意有点迷(或者是我语文不好),但其实实际上求的就是图中连通块的个数,然后在连通块与连通块之间连边建图跑最小生成树.但是……这个图可能是不连通的……求桥的数量和总长 于是我立刻想到 ...

  4. python爬虫-url

    特此声明: 以下内容来源于博主:http://blog.csdn.net/pleasecallmewhy                                     http://cuiq ...

  5. 创建表空间及用户的SQL

    --创建表SOFA空间: CREATE SMALLFILE TABLESPACE "SOFA" DATAFILE 'G:\oracle\product\10.2.0\ORADATA ...

  6. Java -- JDBC mysql读写大数据,文本 和 二进制文件

    1. 往mysql中读写字符文本 public class Demo1 { /* 创建数据库 create database LOBTest; use LOBTest; create table te ...

  7. QT 利用QSplitter 分割区域, 并添加QScrollArea 滚动区域,滚动条

    1. QSplitter 分割区域, 可以分割区域中可以随意添加自己的布局 2. #include "dialog.h" #include <QApplication> ...

  8. DB处理大量数据处理日志报错问题

     因为当插入.更新或删除大批量数据的时候,有时候会出现事务日志满的问题,所以解决步骤 1.连接到当前数据库 db2 connect to uppdb 2.查看数据库配置文件 db2 get db cf ...

  9. oracle创建存储过程中遇到的问题

    create or replace PROCEDURE CLEAR AS tname varchar(200);BEGIN tname:='''immediate trace name flush_c ...

  10. review35

    使用Thread创建线程通常使用的方法是:Thread(Runnable target).该构造方法中的参数是一个Runnable类型的接口,因此在创建线程对象时必须向构造方法的参数传递一个实现Run ...