HDU 1560 DNA sequence (迭代加深搜索)

时间:2023-01-21 13:04:27
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.

HDU 1560 DNA sequence (迭代加深搜索)

InputThe 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.OutputFor 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

思路
如果DNA最长的串长度为n,那就先搜索以n为长度,是否存在符合条件的母串,若不存在,再搜索n+1;
这便是所谓的迭代加深搜索。结束。
代码中用到的maxx,只是一个剪枝而已。
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#define fuck(x) cout<<#x<<" = "<<x<<endl;
#define ls (t<<1)
#define rs ((t<<1)+1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = ;
const int inf = 2.1e9;
const ll Inf = ;
const int mod = 1e9+;
const double eps = 1e-; char s[][];
int maxs=;
int tot[];
int n,pos[];
char a[]="ACGT"; void view()
{
for(int i=;i<=n;i++){
cout<<pos[i]<<" ";
}
cout<<endl;
} bool dfs(int t)
{ int maxx=;
for(int i=;i<=n;i++){
maxx=max(maxx,tot[i]-pos[i]);
}
if(maxx==){return true;}
if(t+maxx>maxs){return false;}
bool vis[];
for(int i=;i<;i++){
memset(vis,,sizeof(vis));
for(int j=;j<=n;j++){
if(s[j][pos[j]]==a[i]){
pos[j]++;
vis[j]=true;
}
}
if(dfs(t+)){return true;}
for(int j=;j<=n;j++){
if(vis[j]){
pos[j]--;
}
}
}
return false;
} int main()
{
int T;
scanf("%d",&T);
while(T--){
scanf("%d",&n);
maxs=;
for(int i=;i<=n;i++){
scanf("%s",s[i]);
tot[i]=strlen(s[i]);
maxs=max(maxs,tot[i]);
} while(true){
memset(pos,,sizeof(pos));
if(dfs()){
printf("%d\n",maxs);
break;
}
else maxs++;
}
}
return ;
}

 

HDU 1560 DNA sequence (迭代加深搜索)的更多相关文章

  1. hdu 1560 DNA sequence&lpar;迭代加深搜索&rpar;

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

  2. HDU 1560 DNA sequence(DNA序列)

    HDU 1560 DNA sequence(DNA序列) Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K  ...

  3. HDU 1560 DNA sequence &lpar;IDA&ast; 迭代加深 搜索&rpar;

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

  4. hdu 1560 DNA sequence&lpar;搜索&rpar;

    http://acm.hdu.edu.cn/showproblem.php?pid=1560 DNA sequence Time Limit: 15000/5000 MS (Java/Others)  ...

  5. HDU 1560 DNA sequence&lpar;IDA&ast;&rpar;

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1560 题目大意:给出n个字符串,让你找一个字符串使得这n个字符串都是它的子串,求最小长度. 解题思路: ...

  6. HDU 1560 DNA sequence DFS

    题意:找到一个最短的串,使得所有给出的串是它的子序列,输出最短的串的长度,然后发现这个串最长是40 分析:从所给串的最长长度开始枚举,然后对于每个长度,暴力深搜,枚举当前位是哪一个字母,注意剪枝 注: ...

  7. HDU - 1560 DNA sequence

    给你最多8个长度不超过5的DNA系列,求一个包含所有系列的最短系列. 迭代加深的经典题.(虽然自己第一次写) 定一个长度搜下去,搜不出答案就加深大搜的限制,然后中间加一些玄学的减枝 //Twenty ...

  8. HDU 1560 DNA sequence A&ast; 难度&colon;1

    http://acm.hdu.edu.cn/showproblem.php?pid=1560 仔细读题(!),则可发现这道题要求的是一个最短的字符串,该字符串的不连续子序列中包含题目所给的所有字符串 ...

  9. HDU1560&lpar;迭代加深搜索&rpar;

    DNA sequence Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

随机推荐

  1. 三个linux系统共存,修改默认启动

     一个mint,一个ubuntu,想要默认启动ubuntu,那么咱们这么来:修改启动顺序,我们需要修改Ubuntu的GRUB配置文件.使用常见的编辑程序如"gedit"就可以很方便 ...

  2. Stronger &lpar;What Doesn't Kill You&rpar;

    今天听一个歌曲,挺不错的.以前一直不知道意思.这次把歌词摘抄下来. 试听音乐: 原版MV: You know the bed feels warmer 你知道被窝里的温暖 Sleeping here ...

  3. PostgreSQL中字符串相关问题

    PostgreSQL的字符串类型有character.character varying和text的值.在使用character类型的时候, 它有自动填充空白的潜在影响,特别是在其它数据库(MySQL ...

  4. 约瑟夫环的java实现

    转自:http://www.cnblogs.com/timeng/p/3335162.html 约瑟夫环:已知n个人(以编号1,2,3...n分别表示)围坐在一张圆桌周围.从编号为k的人开始报数,数到 ...

  5. How to manage and balance &OpenCurlyDoubleQuote;Huge Data Load” for Big Kafka Clusters---reference

    1. Add Partition Tool Partitions act as unit of parallelism. Messages of a single topic are distribu ...

  6. 问题:编译eshoponcontainers失败,提示error&colon;invalid reference format

    环境: visual studio 2017 v15.4.2,docker ce Version 17.06.0-ce-win19 (12801) 参考问题页: https://github.com/ ...

  7. rpm检验是否被改动过

    参考原文http://vbird.dic.ksu.edu.tw/linux_basic/0520rpm_and_srpm.php#rpmmanager_verify   rpm -qVa   (当然可 ...

  8. 自己封装element-ui树组件的过滤

    前言:vue开发项目时用到了element-ui的树组件,但是发现一执行过滤事件,树就全部都展开了,为了解决这个问题,只能自己先过滤数剧,再赋值给树组件的data,就避免了一上来全部展开的尴尬. 一. ...

  9. &lbrack;svc&rsqb;tomcat目录结构&sol;虚拟主机&sol;nginx反向代理cache配置

    tomcat目录文件 /usr/local/tomcat/bin/catalina.sh stop sleep 3 /usr/local/tomcat/bin/catalina.sh start to ...

  10. spark submit 入门

    spark dirver本质是一个spark集群的驱动程序,你要调用spark集群的计算功能,必须要通过它! from pyspark import SparkConf, SparkContext c ...