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.

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(迭代加深搜索)

    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 (IDA* 迭代加深 搜索)

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

  4. hdu 1560 DNA sequence(搜索)

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

  5. HDU 1560 DNA sequence(IDA*)

    题目链接: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* 难度:1

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

  9. HDU1560(迭代加深搜索)

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

随机推荐

  1. adoquery怎样判断数据在缓存中有修改啊

    ADOQry.Filtered:=false;       ADOQry.Filtered:=true;       ADOQry.FilterGroup:=fgPendingRecords ;Fil ...

  2. delphi中如何实现DBGrid中的两列数据想减并存入另一列

    可参考下面的例子:   数据自动计算的实现:“金额”是由“单价”和“工程量”相乘直接得来的,勿需人工输入. 这可在“数据源构件”的onupdatedata例程添加如下代码实现: procedure T ...

  3. mysql数据库,安装 !创建!...详解!

    package cn.jiayou; /* 一.mysql? a.MySQL是Web世界中使用最广泛的数据库服务器. SQLite的特点? 1.是轻量级.可嵌入,但不能承受高并发访问,适合桌面和移动应 ...

  4. 表单中input name属性有无[]的区别

    1 input数组 如下一个表单: <input type="text" name="username[]" value="Jason" ...

  5. gauss——seidel迭代

    转载:https://blog.csdn.net/wangxiaojun911/article/details/6890282 Gauss–Seidelmethod 对应于形如Ax = b的方程(A为 ...

  6. c++ 动态生成string类型的数组

    定义一个字符串指针,将其初始化为空 char *a=NULL 然后输入输出 cin>>a cout<<a 编译无误,但执行会遇见错误 当为*a动态分配存储空间时,程序执行正常 ...

  7. ZOJ 1403 解密

    参考自:https://www.cnblogs.com/ECJTUACM-873284962/p/6412212.htmlSafecracker Time Limit: 2 Seconds       ...

  8. 洛谷P2512 糖果传递

    环形均分纸牌 普通的均分纸牌前缀和的总和就是答案. 但是这里是环形的,要断开的位置需要最佳,我们把每个数减去sum/n,这样总的前缀和就为0了,若在第k个数之后把环断开,环形前缀和可以统一写成s[i] ...

  9. 基于FPGA的VGA接口使用

    前言 什么是VGA? VGA(视频图形阵列)是IBM公司制定的一种视频数据传输标准. 接口信号主要有5个:R(Red),G(Green),B(Blue),HS(Horizontal synchroni ...

  10. 【XSY2523】神社闭店之日 莫比乌斯反演

    题目大意 给你\(a_1\ldots a_n,l,c\)每次给你\(x,y\),求有多少个序列满足:长度\(\leq l\),每个元素是\([1,c]\),循环右移\(a_j(x\leq j\leq ...