DNA sequence

Time Limit : 15000/5000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 15   Accepted Submission(s) : 7

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

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

————————————————————————————————————————————————
题意:从n个串中找出一个最短的公共串(也许应该说序列吧,因为不要求连续,即只要保持相对顺序就好)。



分析:迭代加深搜索,就是每次都限制了DFS的深度,若搜不到答案,则加深深度,继续搜索,这样就防止了随着深度不断加深而进行的盲目搜索,而且,对于这种求最短长度之类的题目,只要找到可行解,即是最优解了。所以就这样敲完代码了,敲完之后,悲剧TLE。



少了一步十分重要的剪枝,就是每次DFS的时候,都要判断一下,当前的深度+最少还有加深的深度是否大于限制的长度,若是,则退回。



#include <iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<algorithm>
using namespace std;
char s[10][10];
int n,mx,flag;
char ch[5]={'A','T','C','G'}; void dfs(int deep,int *cnt)
{
if(flag)
return;
int sum=0;
int maxlen=0;
int a;
for(int i=0; i<n; i++)
{
a=strlen(s[i])-cnt[i];
sum=sum+a;
maxlen=max(maxlen,a);
}
if(maxlen+deep>mx)
return;
if(sum==0)
{
flag=1;
return;
}
int fl=0;
int next[10];
for(int i=0; i<4; i++)
{
for(int j=0; j<n; j++)
{
if(s[j][cnt[j]]==ch[i])
{
fl=1;
next[j]=cnt[j]+1;
}
else
next[j]=cnt[j];
}
if(fl)
{
dfs(deep+1,next);
}
if(flag)
return;
} } int main()
{
int o,k;
int cnt[10];
scanf("%d",&o);
while(o--)
{
scanf("%d",&n);
mx=0;
for(int i=0; i<n; i++)
{
scanf("%s",s[i]);
k=strlen(s[i]);
mx=max(mx,k);
}
memset(cnt,0,sizeof(cnt));
flag=0;
for(int i=0; i<40; i++)
{
dfs(0,cnt); if(flag)
break;
mx++;
}
printf("%d\n",mx);
}
return 0;
}

Hdu1560 DNA sequence(IDA*) 2017-01-20 18:53 50人阅读 评论(0) 收藏的更多相关文章

  1. NYOJ-102 次方求模 AC 分类: NYOJ 2014-02-06 18:53 184人阅读 评论(0) 收藏

    地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=102 //a^b mod c=(a mod c)^b mod c很容易设计出一个基于二分的递归 ...

  2. ZEDBOARD启动自启配置(加载镜像) 分类: OpenCV ubuntu shell ZedBoard Eye_Detection 2014-11-08 18:53 167人阅读 评论(0) 收藏

    参考:陆书14.2.8 1)备份ramdisk8M.image.gz 2)加载rootfs镜像文件: 3)在镜像目录下建立自己所需文件夹(挂载目录): 我需要的挂载目录有两个: root/qt/ins ...

  3. c++map的用法 分类: POJ 2015-06-19 18:36 11人阅读 评论(0) 收藏

    c++map的用法 分类: 资料 2012-11-14 21:26 10573人阅读 评论(0) 收藏 举报 最全的c++map的用法 此文是复制来的0.0 1. map最基本的构造函数: map&l ...

  4. 团体程序设计天梯赛L2-003 月饼 2017-03-22 18:17 42人阅读 评论(0) 收藏

    L2-003. 月饼 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 月饼是中国人在中秋佳节时吃的一种传统食品,不同地区有许多不 ...

  5. HDU6205 Coprime Sequence 2017-05-07 18:56 36人阅读 评论(0) 收藏

    Coprime Sequence                                                        Time Limit: 2000/1000 MS (Ja ...

  6. 移植QT到ZedBoard(制作运行库镜像) 交叉编译 分类: ubuntu shell ZedBoard OpenCV 2014-11-08 18:49 219人阅读 评论(0) 收藏

    制作运行库 由于ubuntu的Qt运行库在/usr/local/Trolltech/Qt-4.7.3/下,由makefile可以看到引用运行库是 INCPATH = -I/usr//mkspecs/d ...

  7. highgui.h备查 分类: C/C++ OpenCV 2014-11-08 18:11 292人阅读 评论(0) 收藏

    /*M/////////////////////////////////////////////////////////////////////////////////////// // // IMP ...

  8. HDU6023 Automatic Judge 2017-05-07 18:30 73人阅读 评论(0) 收藏

    Automatic Judge Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others ...

  9. Pots 分类: 搜索 POJ 2015-08-09 18:38 3人阅读 评论(0) 收藏

    Pots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11885 Accepted: 5025 Special Judge D ...

随机推荐

  1. SQL Server中动态列转行

    http://www.cnblogs.com/gaizai/p/3753296.html 一.本文所涉及的内容(Contents) 本文所涉及的内容(Contents) 背景(Contexts) 实现 ...

  2. 租用游艇(简单区间dp)

    租用游艇 时间限制: 1 Sec  内存限制: 128 MB提交: 1  解决: 1[提交][状态][讨论版][命题人:quanxing] 题目描述 长江游艇俱乐部在长江上设置了n 个游艇出租站1,2 ...

  3. [Android] 开发第九天

    以下代码完全使用代码来控制 UI 界面,不被推荐使用. package com.oazzz.test2; import android.graphics.LinearGradient; import ...

  4. django-聚合操作

    聚合操作就是对数据库的数值类型操作的方法 avg,sum,max,min,count select avg(age) from students  # 求年龄平均值  django中的聚合操作 1.a ...

  5. unicat,multicast,broadcast区别

    单播.多播和广播单播”(Unicast).“多播”(Multicast)和“广播”(Broadcast)这三个术语都是用来描述网络节点之间通讯方式的术语.那么这些术语究竟是什么意思?区别何在? 1.单 ...

  6. C细节学习

    字符串ascii码值比较compress函数;

  7. 好记性不如烂笔头-linux学习笔记6keepalived实现主备操作

    Keepalived的作用是检测服务器的状态,如果有一台web服务器宕机,或工作出现故障,Keepalived将检测到,并将有故障的服务器从系统中剔除,同时使用其他服务器代替该服务器的工作,当服务器工 ...

  8. C#中StreamWriter与BinaryWriter的区别兼谈编码。

    原文:http://www.cnblogs.com/ybwang/archive/2010/06/12/1757409.html 参考: 1. <C#高级编程>第六版 2.  文件流和数据 ...

  9. PowerDesigner 生成的脚本取掉双引号

    建模工具PowerDesigner http://www.cnblogs.com/mcgrady/archive/2013/05/25/3098588.html 默认导出在带双引号,表名称后期使用的时 ...

  10. 可视化库-Matplotlib-Pandas与sklearn结合(第四天)

    1. 计算每一种的比例的百分比 import pandas as pd from matplotlib.ticker import FuncFormatter np.random.seed(0) df ...