DNA sequence

Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4217    Accepted Submission(s): 2020

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
 
Author
LL
 
Source
 
Recommend
LL
 
题意:现在我们给定了数个DNA序列,请你构造出一个最短的DNA序列,使得所有我们给定的DNA序列都是它的子序列。例如,给定"ACGT","ATGC","CGTT","CAGT",你可以构造的一个最短序列为"ACAGTGCT",但是需要注意的是,这并不是此问题的唯一解。
思路: *IDA  若当前长度+最长构造长度< 迭代的最大深度则return 进行良好剪枝
accode
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<sstream>
#include<cstring>
#include<string>
#include<vector>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<cmath>
#include<algorithm>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
#define MAX_N 1000005
#define gcd(a,b) __gcd(a,b)
#define mem(a,x) memset(a,x,sizeof(a))
#define mid(a,b) a+b/2
#define stol(a) atoi(a.c_str())//string to long
string temp[];
string c = "ACGT";
int pos[];
int len[];
int deep;
int n;
int ans(){
int maxn = ;
for(int i = ; i < n; i++){
maxn = max(maxn,len[i]-pos[i]);
}
return maxn;
}
int dfs(int step){
if(step + ans() > deep)
return ;
if(!ans())//满足构造序列包含所有序列
return ;
int temp1[];
for(int i = ; i < ; i++){ int flag = ;
for(int j = ; j < n; j++)
temp1[j] = pos[j]; for(int j = ; j < n; j++){
if(temp[j][pos[j]] == c[i]){
flag = ;
pos[j]++;
}
}
if(flag){
if(dfs(step+))
return ;
for(int j = ; j < n; j++)
pos[j] = temp1[j];
}
}
return ;
}
int main(){
// freopen("D:\\in.txt","r",stdin);
int T;
scanf("%d",&T);
while(T--){
scanf("%d",&n);
deep = ;
for(int i = ; i < n; i++){
cin>>temp[i];
len[i] = temp[i].length();
pos[i] = ;
deep = max(deep,len[i]);
}
while(){
if(dfs())
break;
++deep;
}
printf("%d\n",deep);
}
return ;
}

DNA sequence HDU - 1560的更多相关文章

  1. DNA sequence HDU - 1560(IDA*,迭代加深搜索)

    题目大意:有n个DNA序列,构造一个新的序列,使得这n个DNA序列都是它的子序列,然后输出最小长度. 题解:第一次接触IDA*算法,感觉~~好暴力!!思路:维护一个数组pos[i],表示第i个串该匹配 ...

  2. IDA*、剪枝、较难搜索、扫描——DNA sequence HDU - 1560

    万恶之源 翻译 题意就是给出N个DNA序列,要求出一个包含这n个序列的最短序列是多长 这是一道搜索题,为什么呢?从样例可以感受到,我们应该从左往右"扫描",从n个DNA序列中取出某 ...

  3. G - DNA sequence HDU - 1560

    题目链接: https://vjudge.net/contest/254151#problem/G AC代码: #include<iostream> #include<cstring ...

  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(DNA序列)

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

  6. hdu 1560 DNA sequence(迭代加深搜索)

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

  7. 【HDU - 1560】DNA sequence (dfs+回溯)

    DNA sequence 直接中文了 题目描述 21世纪是生物科技飞速发展的时代.我们都知道基因是由DNA组成的,而DNA的基本组成单位是A,C,G,T.在现代生物分子计算中,如何找到DNA之间的最长 ...

  8. HDU1560 DNA sequence —— IDA*算法

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1560 DNA sequence Time Limit: 15000/5000 MS (Java/Oth ...

  9. POJ 2778 DNA Sequence(AC自动机+矩阵加速)

    DNA Sequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9899   Accepted: 3717 Desc ...

随机推荐

  1. LeetCode No.103,104,105

    No.103 ZigzagLevelOrder 二叉树的锯齿形层次遍历 题目 给定一个二叉树,返回其节点值的锯齿形层次遍历.(即先从左往右,再从右往左进行下一层遍历,以此类推,层与层之间交替进行). ...

  2. Git ubuntu 升级

    外文文档 This team will distribute the most current stable package of Git for Ubuntu. Stable releases: h ...

  3. PAT甲级——1011 World Cup Betting

    PATA1011 World Cup Betting With the 2010 FIFA World Cup running, football fans the world over were b ...

  4. 必应翻译:让Windows上的翻译不再是难事

    文章译自:Translations Made Easy on Windows 比方说今年夏天你想出国旅行,计划去一趟德国.你的行程很丰富:参观慕尼黑和柏林,乘坐游船沿莱茵河而下,再品尝几串摩泽尔的葡萄 ...

  5. swift中的category,扩展

    1.创建选择 :swift file 2.名称:UIBarButtonItem-Extension 3.category,便利构造函数 extension UIColor { /* 1.extensi ...

  6. python3下scrapy爬虫(第九卷:scrapy数据存储进JSON文件)

    将爬取数据存储在JSON文件里并不难,只需修改pipelines文件 直接看代码: 来看下结果: 中文字符恶心的很 之后我会在后卷中做出修改

  7. verilog乘法器的设计

    在verilog编程中,常数与寄存器变量的乘法综合出来的电路不同于寄存器变量乘以寄存器变量的综合电路.知乎里的解释非常好https://www.zhihu.com/question/45554104, ...

  8. AUTO Uninstaller 常见问题

    小伙伴是不是遇到 CAD/3dmax/maya/Revit/Inventor 安装失败或者安装不了的问题了呢?AUTODESK系列软件着实令人头疼,CAD/3dmax/maya/Revit/Inven ...

  9. python中sort和sorted排序的相关方法

    Python list内置sort()方法用来排序,也可以用python内置的全局sorted()方法来对可迭代的序列排序生成新的序列. 1)排序基础 简单的升序排序是非常容易的.只需要调用sorte ...

  10. Redhat7 配置https

    Redhat7 配置https 分为自签名证书和第3方证书(此时实验为第3方,自签名略) 安装: # yum install httpd mod_ssl 生成key: # openssl genrsa ...