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. 工程师常犯的web后台界面用户体验错误

  2. ERP行业内幕看了这五个问题全懂了

    ERP系统是现代企业实现信息化管理的必经之路.但很多管理人员或已经在用ERP的人员,其实并不太懂ERP系统是什么意思,有哪些好处等,导致实际使用过程中经常大材小用,或者“英雄无用武之地”.所以,为了更 ...

  3. mysql分页查询按某类型置顶 按某类型置尾 再按优先级排序

    近段时间接到一个新需求: 第一优先级:未满的标的顺位高于已满标的顺位.第二优先级:新手标的顺位高于其他标的的顺位. 第三优先级:标的剩余可投金额少的顺位高于标的剩余可投金额多的. 我是直接通过sql语 ...

  4. 3.docker基础架构

    docker是一个典型的c/s架构产品. dockerd :为客户端提供  RESTFUL API,响应来自客户端的请求, 采用模块化的架构, 通过专门的 Engine 模块来分发管理各 个来自客户端 ...

  5. CML\LVDS

    LVDS和CML电平应用区别 https://wenku.baidu.com/view/6bb0066f011ca300a6c3908c.html

  6. hdu-1238(kmp+枚举)

    题意:给你n个字符串,问你这里面最长的公共子串的长度是多少,一个公共子串的反串也算,比如样例二: 解题思路:随便找一个字符,枚举它的子串然后跑kmp就行了,很多人的博客都是用string类里面的函数来 ...

  7. 牛客网-2018年湘潭大学程序设计竞赛-F

    题目链接:https://www.nowcoder.com/acm/contest/105/F 解题思路:这道题第一眼直接思路就是搜索,但想了半天没想到有什么好办法搜,然后就转成最短路写了, 因为多入 ...

  8. 我踩过的Alwayson的坑!

    最近被sql server Alwayson高可用组和读写分离,弄得神魂颠倒,身心俱疲.遇到了下面一些问题,提醒自己也给后来人做些记录. EntityFramework支不支持Alwayson? 起因 ...

  9. fpm 打包工具安装调试

    https://github.com/jordansissel/fpm  官方git yum install ruby-devel gcc make rpm-build rubygems gem so ...

  10. kvm 一些web管理3方工具

    OpenNebula  Proxmox VE