博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 3080 KMP
阅读量:6087 次
发布时间:2019-06-20

本文共 3521 字,大约阅读时间需要 11 分钟。

Blue Jeans
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 11564   Accepted: 4969

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

32GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA3GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATAGATACTAGATACTAGATACTAGATACTAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAAGATACCAGATACCAGATACCAGATACCAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA3CATCATCATCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCACATCATCATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACATCATCATTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT

Sample Output

no significant commonalitiesAGATACCATCATCAT

 

 

题目大意:找几个字串的最长公共子串。如小于3则输出no siginificant commonalities

 

思路:

用其他的字符串对每一个字串的后缀进行匹配,计录每个字串能匹配到的最大长度,然后所有串取min.

再把所有后缀的min取个max即可

 

#include
#include
#include
#include
#include
using namespace std;int a[21][71];int s[71],next[71];int m,ap,ple,xzq,n,i,j,k,x,z,q,t,l,T;char c;bool p;void Read(){ m=0; while(c=getchar(),c<'A'||c>'Z'); a[i][++m]=c; while(c=getchar(),c>='A'&&c<='Z'){ a[i][++m]=c; if(m==60)break; }}bool compare(int x,int z,int q){ int i; for(i=1;i<=q;i++){ if(a[1][x+i-1]
a[1][z+i-1])return false; } return false;}int main(){ scanf("%d",&t); for(T=1;T<=t;T++){ memset(a,0,sizeof(a)); xzq=0; scanf("%d",&n); for(i=1;i<=n;i++){ Read(); } for(i=1;i<=58;i++){ for(j=i;j<=60;j++)s[j-i+1]=a[1][j]; l=60-i+1; memset(next,0,sizeof(next)); x=0; for(j=2;j<=l;j++){ while(x!=0&&s[j]!=s[x+1])x=next[x]; if(s[j]==s[x+1])x++; next[j]=x; } ple=0; for(j=2;j<=n;j++){ ap=0; x=0; for(k=1;k<=60;k++){ while(x!=0&&a[j][k]!=s[x+1])x=next[x]; if(a[j][k]==s[x+1])x++; if(x>ap)ap=x; if(x==l)x=next[x]; } if(ple==0||ap
xzq){ xzq=ple; z=i; q=ple; } else if(ple==xzq){ p=compare(z,i,ple); if(p==false){ z=i; q=ple; } } } if(xzq<3)printf("no significant commonalities\n"); else{ for(i=z;i

 

转载于:https://www.cnblogs.com/applejxt/p/3801565.html

你可能感兴趣的文章
Linux开机启动时执行脚本的方法
查看>>
pgsql数据库应用两点注意
查看>>
linux下查看CPU、内存、磁盘信息
查看>>
25幅精美绝伦的光涂鸦摄影作品
查看>>
C++设计模式
查看>>
存储过程添加事务
查看>>
求一段CSS样式代码;要求是Table的标签样式,实现Table标签奇数行显示一个颜色;偶数行显示另外一种颜色...
查看>>
37个超级棒的 jQuery菜单插件
查看>>
怎样使窗体中的控件布局统一?
查看>>
Web Service学习笔记:动态调用WebService的方法总结
查看>>
SQL Server 2012将与Hadoop无缝集成
查看>>
有线+无线路由器设置
查看>>
正则表达式入门教程
查看>>
poj1111
查看>>
NYOJ-107 A Famous ICPC Team
查看>>
wubi安装ubuntu后,增加swap大小,优化swap的使用参数-----------让ubuntu健步如飞,为编译android源码准备...
查看>>
基于模糊集理论的一种图像二值化算法的原理、实现效果及代码
查看>>
十三种基于直方图的图像全局二值化算法原理、实现、代码及效果。
查看>>
与众不同 windows phone (44) - 8.0 位置和地图
查看>>
MVC4数据注释与验证 2
查看>>