Time Limit: 1000MS
Memory Limit: 65536K

Total Submissions: 19026
Accepted: 8466

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 individual 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

Source

South Central USA 2006

【翻译】给出一些字符串,找出最长公共连续子串,并且输出字典序最小的那个,如果最优解长度小于3,输出no significant commonalities。

题解:

       ①串长度不超过60,因此考虑暴力枚举第一个串的子串。

       ②在上文的情况下,将当前枚举的子串与剩下的字符串匹配就可以了。

       ③为了找到字典序最小,这里直接用STL-string操作比较方便。

#include<string>
#include<stdio.h>
#include<cstring>
#include<iostream>
#define go(i,a,b) for(int i=a;i<=b;i++)
#define ro(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int N=100;string ans,tmp;
int t,n,m,C,len,ok,OK,f[N];
char s[15][N],T[N],P[N];
bool KMP_Matching()
{
int j;f[0]=f[1]=0;
go(i,1,m-1){j=f[i];while(j&&P[i]!=P[j])j=f[j];f[i+1]=P[i]==P[j]?j+1:0;}j=0;
go(i,0,n-1){while(j&&P[j]!=T[i])j=f[j];if((j+=P[j]==T[i])==m)return 1;}
return 0;
}
int main()
{
scanf("%d",&C);
while(C--&&scanf("%d",&t))
{
go(i,1,t)scanf("%s",s[i]);
ans="";len=strlen(s[1]);
ro(k,len,1)
{
OK=0;
go(i,0,len-k)
{
ok=1;m=0;
go(u,i,i+k-1)P[m++]=s[1][u];
go(j,2,t)
{
n=strlen(s[j]);
go(u,0,n-1)T[u]=s[j][u];
if(!(ok&=KMP_Matching()))break;
}
if(ok)
{
OK=1;tmp.clear();go(u,0,m-1)tmp+=P[u];
if(ans==""||tmp<ans)ans=tmp;
}
}
if(OK)
{
if(ans.length()>=3)cout<<ans<<endl;
else puts("no significant commonalities");goto Judy;
}
}
puts("no significant commonalities");Judy:;
}
return 0;
}//Paul_Guderian

谁能告诉我那奔腾的迷惘与骄傲,

是否就是我心底永隔一世的河流。——————汪峰《河流》

最新文章

  1. Sentiment Analysis resources
  2. JavaScript易错点
  3. 解决Windows 8系统假死的方法
  4. springMVC 拦截器简单配置
  5. jQuery对表单、表格的操作及更多应用(中:表格应用)
  6. java基础知识(一)
  7. CentOS通过yum安装php7.0
  8. Android Studio代码行数统计插件Statistics
  9. 【论文阅读】Deep Mixture of Diverse Experts for Large-Scale Visual Recognition
  10. 201671010142 java类与对象的定义及使用
  11. P3258 [JLOI2014]松鼠的新家 (简单的点差分)
  12. Django url配置 正则表达式详解 分组命名匹配 命名URL 别名 和URL反向解析 命名空间模式
  13. 关于视觉跟踪中评价标准的相关记录(The Evaluation of Visual Tracking Results on OTB-100 Dataset)
  14. dUMP:A new value is to be assigned to the field &quot;&lt;L_BOX&gt;&quot;
  15. php魔术方法__tostring的应用
  16. SM2
  17. ubuntu 下jdk安装配置
  18. shell编写总结
  19. Defining Python Source Code Encodings
  20. jQuery——表单异步提交

热门文章

  1. docker快速安装jenkins
  2. Linux - 用户环境变量的查看与设置
  3. Oracle客户端安装配置
  4. Linux apt & yum 及 常用命令
  5. 右键git-bash不能使用
  6. paramiko基本操作
  7. PAT Basic 1057
  8. P2985 [USACO10FEB]吃巧克力Chocolate Eating
  9. convlstm学习资料
  10. 最“高大上”的Spring测试:Spring Test