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

  1. 3
  2. 2
  3. GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATA
  4. AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
  5. 3
  6. GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATA
  7. GATACTAGATACTAGATACTAGATACTAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA
  8. GATACCAGATACCAGATACCAGATACCAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA
  9. 3
  10. CATCATCATCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
  11. ACATCATCATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
  12. AACATCATCATTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT

Sample Output

  1. no significant commonalities
  2. AGATAC
  3. CATCATCAT

Source

South Central USA 2006

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

题解:

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

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

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

  1. #include<string>
  2. #include<stdio.h>
  3. #include<cstring>
  4. #include<iostream>
  5. #define go(i,a,b) for(int i=a;i<=b;i++)
  6. #define ro(i,a,b) for(int i=a;i>=b;i--)
  7. using namespace std;
  8. const int N=100;string ans,tmp;
  9. int t,n,m,C,len,ok,OK,f[N];
  10. char s[15][N],T[N],P[N];
  11. bool KMP_Matching()
  12. {
  13. int j;f[0]=f[1]=0;
  14. 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;
  15. go(i,0,n-1){while(j&&P[j]!=T[i])j=f[j];if((j+=P[j]==T[i])==m)return 1;}
  16. return 0;
  17. }
  18. int main()
  19. {
  20. scanf("%d",&C);
  21. while(C--&&scanf("%d",&t))
  22. {
  23. go(i,1,t)scanf("%s",s[i]);
  24. ans="";len=strlen(s[1]);
  25. ro(k,len,1)
  26. {
  27. OK=0;
  28. go(i,0,len-k)
  29. {
  30. ok=1;m=0;
  31. go(u,i,i+k-1)P[m++]=s[1][u];
  32. go(j,2,t)
  33. {
  34. n=strlen(s[j]);
  35. go(u,0,n-1)T[u]=s[j][u];
  36. if(!(ok&=KMP_Matching()))break;
  37. }
  38. if(ok)
  39. {
  40. OK=1;tmp.clear();go(u,0,m-1)tmp+=P[u];
  41. if(ans==""||tmp<ans)ans=tmp;
  42. }
  43. }
  44. if(OK)
  45. {
  46. if(ans.length()>=3)cout<<ans<<endl;
  47. else puts("no significant commonalities");goto Judy;
  48. }
  49. }
  50. puts("no significant commonalities");Judy:;
  51. }
  52. return 0;
  53. }//Paul_Guderian

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

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

【POJ 3080 Blue Jeans】的更多相关文章

  1. POJ 3080 Blue Jeans (求最长公共字符串)

    POJ 3080 Blue Jeans (求最长公共字符串) Description The Genographic Project is a research partnership between ...

  2. POJ 3080 Blue Jeans(Java暴力)

    Blue Jeans [题目链接]Blue Jeans [题目类型]Java暴力 &题意: 就是求k个长度为60的字符串的最长连续公共子串,2<=k<=10 规定: 1. 最长公共 ...

  3. poj 3080 Blue Jeans

    点击打开链接 Blue Jeans Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10243   Accepted: 434 ...

  4. POJ 3080 Blue Jeans (字符串处理暴力枚举)

    Blue Jeans  Time Limit: 1000MS        Memory Limit: 65536K Total Submissions: 21078        Accepted: ...

  5. POJ 3080 Blue Jeans 找最长公共子串(暴力模拟+KMP匹配)

    Blue Jeans Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20966   Accepted: 9279 Descr ...

  6. poj 3080 Blue Jeans【字符串处理+ 亮点是:字符串函数的使用】

    题目:http://poj.org/problem?id=3080 Sample Input 3 2 GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCA ...

  7. POJ - 3080 Blue Jeans 【KMP+暴力】(最大公共字串)

    <题目链接> 题目大意: 就是求k个长度为60的字符串的最长连续公共子串,2<=k<=10 限制条件: 1.  最长公共串长度小于3输出   no significant co ...

  8. POJ 3080 Blue Jeans(后缀数组+二分答案)

    [题目链接] http://poj.org/problem?id=3080 [题目大意] 求k个串的最长公共子串,如果存在多个则输出字典序最小,如果长度小于3则判断查找失败. [题解] 将所有字符串通 ...

  9. poj 3080 Blue Jeans 解题报告

    题目链接:http://poj.org/problem?id=3080 该题属于字符串处理中的串模式匹配问题.题目要求我们:给出一个DNA碱基序列,输出最长的相同的碱基子序列.(保证在所有的序列中都有 ...

随机推荐

  1. udp发送广播消息

    import socket if __name__ == '__main__': # 创建udpsocket udp_socket = socket.socket(socket.AF_INET, so ...

  2. 39条常见的Linux系统简单面试题

    39条常见的Linux系统简单面试题 本文主要分享39条常见的Linux系统简单面试题,其中包括如何看当前Linux系统有几颗物理CPU和每颗CPU的核数.如何实时查看网卡流量为多少等等,希望对你有所 ...

  3. Docker迁移学习及其他

    起因: 有在一台服务器A上通过docker搭建git服务,由于某些原因需要将其迁移到另一台服务器B. 过程: 最终采用方式: 首先通过docker ps(-a) 查看目标容器,然后通过commit命令 ...

  4. thinkphp5,单图,多图,上传

    /** * 上传单图 */ function upload($path, $filename) { $file = request()->file($filename); $info = $fi ...

  5. php-5.6.26源代码 - 扩展模块的加载、注册

    // main实现在文件 php-5.6.26\sapi\cgi\cgi_main.c int main(int argc, char *argv[]) { .... cgi_sapi_module- ...

  6. 10.2 DOM 操作技术【JavaScript高级程序设计第三版】

    很多时候,DOM 操作都比较简明,因此用JavaScript 生成那些通常原本是用HTML 代码生成的内容并不麻烦.不过,也有一些时候,操作DOM 并不像表面上看起来那么简单.由于浏览器中充斥着隐藏的 ...

  7. #Python编程从入门到实践#第二章笔记

      ​​​1.变量 (1)变量名只能包含字母.数字和下划线,不能包含空格 (2)不要将python关键字与函数名作为变量名 (3)简短有描述性,避免使用小写字母l和大写字母O (4)python 始终 ...

  8. 深度学习 GPU环境 Ubuntu 16.04 + Nvidia GTX 1080 + Python 3.6 + CUDA 9.0 + cuDNN 7.1 + TensorFlow 1.6 环境配置

    本节详细说明一下深度学习环境配置,Ubuntu 16.04 + Nvidia GTX 1080 + Python 3.6 + CUDA 9.0 + cuDNN 7.1 + TensorFlow 1.6 ...

  9. loadrunner破解出现“license security violation,Operation is not allowed”的错误提示

    1.关闭loadrunner,将破解文件(“lm70.dll”.“mlr5lprg.dll”)放置在LoadRunner\bin下面 2.以管理员身份运行loadrunner,在CONFUGURATI ...

  10. UnitOfWork知多少 【转】

    原文链接:https://www.cnblogs.com/sheng-jie/p/7416302.html 1. 引言 Maintains a list of objects affected by ...