必威体育Betway必威体育官网
当前位置:首页 > IT技术

Blue Jeans(最大匹配问题)

时间:2019-09-26 13:13:13来源:IT技术作者:seo实验室小编阅读:50次「手机版」
 

bluejeans

Description

The Genographic Project is a research partnership between IBM and The National Geographic Society that is analyzing DNA from hundreds of thousands of contributors to map how the Earth was populated.

As an IBM researcher, you have been tasked with writing a program that will find commonalities amongst given snippets of DNA that can be correlated with inpidual survey information to identify new genetic markers.

A DNA base sequence is noted by listing the nitrogen bases in the order in which they are found in the molecule. There are four bases: adenine (A), thymine (T), guanine (G), and cytosine (C). A 6-base DNA sequence could be represented as TAGACC.

Given a set of DNA base sequences, determine the longest series of bases that occurs in all of the sequences.

Input

Input to this problem will begin with a line containing a single integer n indicating the number of datasets. Each dataset consists of the following components:

  • A single positive integer m (2 <= m <= 10) indicating the number of base sequences in this dataset.
  • m lines each containing a single base sequence consisting of 60 bases.

Output

For each dataset in the input, output the longest base subsequence common to all of the given base sequences. If the longest common subsequence is less than three bases in length, display the string "no significant commonalities" instead. If multiple subsequences of the same longest length exist, output only the subsequence that comes first in alphabetical order.

Sample Input

3
2
GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
3
GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATA
GATACTAGATACTAGATACTAGATACTAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA
GATACCAGATACCAGATACCAGATACCAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA
3
CATCATCATCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
ACATCATCATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AACATCATCATTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT

Sample Output

no significant commonalities
AGATAC
CATCATCAT

题目大意:给n组数据,每组给出m串字符串,字符串由ACTG(碱基对)组成,求出这m个串的最大相同子串。

思路:自己硬钢的时候是没有思路的,看了一下下别人的代码,然后发现了自己一直以来对STL中string的使用以及认知方面的漏洞。(例如:find()==string::npos   。string s=a[0].substr(j,i);)。虽然是用了STL但还是是暴力.......题的数据小。(有kmp的冲动,不敢动,不敢动)。

代码如下:

#include<iOStream>
#include<string>
#include<stdio.h>
using namespace std;
string a[1000];
int main()
{
    int t,i,n,j,k;
    cin>>t;
	while(t--)
	{
	    cin>>n;
		string b="";
		for(i=0;i<n;i++)
	    cin>>a[i];
	    for(i=0;i<=60;i++)//此处60为题目要求长度
	    {
		    for(j=0;j<=60;j++)
		    {
			   int p=0;
			   string s=a[0].substr(j,i); //截取下标为j后I位的子串
		       for(k=1;k<n;k++)
		       {
			       if(a[k].find(s)==string::npos) 
			       {
				       p=1;
			           break;
					}
		        }//枚举各串,判断该子串是否为公共子串
	            if(p==0)
	            if(s.size()>b.size()) b=s;
                else if(s.size()==b.size()&&b>s)b=s;
		    }//若为公共子串,进行最长更新
	    }
        if(b.size()<3)
		printf("no significant commonalities\n");
	    else
        cout<<b<<endl;
	}
    return 0;
}

相关阅读

iqair和blueair哪个好?这场battle 有看点

朋友最近想买空气净化器,在iqair和blueair中纠结到底哪个比较好。其实之前买空气净化器之前,我也犹豫了许久,最终选择了blueair。想

BlueMP百变模板在线制作手机网站 企业免费wap自助建站

最近和朋友聊天,听说他的地方站自从建立了手机端论坛,人气就越来越好,由衷地为他高兴。同时,自己维护的微信公众号前一段时间也希望吸

bluehost中国和bluehost美国的区别?应该选择哪个?

bluehost作为著名的美国主机商,为了更好的服务国内用户,与2014年推出了BlueHost中文站,BlueHost中国作为BlueHost美国主机商在国内

BlueCoat ProxySG配置FTP代理

代理模式说明 FTP客户端穿越代理服务器有三种方式: FTP客户端配置通用代理模式 FTP客户端配置FTP代理模式 浏览器直接访问FTP服

蓝牙工具IVT Bluesoleil破解流程

工具1、最新版本IVT_BlueSoleil_10.0.492.12、破解软件Bluesoleil 8.XXX Patch Tool链接:http://pan.baidu.com/s/1jGvXPhc 密

分享到:

栏目导航

推荐阅读

热门阅读