链接:

http://poj.org/problem?id=3080

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88230#problem/E (密码0817)

Blue Jeans
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 14544   Accepted: 6478

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

第一次接触 KMP 算法, 看了一下不是很懂, 感觉是解决字符串匹配的问题,不知道理解是否正确,先粘个代码学习一下

这个就是个暴力加KMP, 子串的长度要大于等于3,相同长度的要字典序最大的

代码:

#include<stdio.h>
#include<string.h> #define N 100 char s[N][N];
int next[N]; void GetNext(char s[])
{
int i=, j=-, n=strlen(s);
next[] = -; while(i<n)
{
if(j==- || s[i]==s[j])
next[++i] = ++j;
else
j = next[j];
}
}
bool KMP(char a[], char s[])
{
int i=, j=;
int Na=strlen(a), Ns=strlen(s); while(i<Na)
{
while(j==- || (a[i]==s[j] && i<Na))
i++, j++; if(j==Ns) return true; j = next[j];
}
return false;
} int main()
{
int t;
scanf("%d", &t);
while(t--)
{
int i, j, len, m, MaxLen = ;
char ans[N]="Z"; scanf("%d", &m); for(i=; i<m; i++)
scanf("%s", s[i]); for(len=; len>=; len--)
for(i=; i<=MaxLen-len; i++) ///枚举第一个串的所有子串
{
char b[N]={}; strncpy(b, s[]+i, len);
GetNext(b); for(j=; j<m; j++)
if(KMP(s[j], b)==false)
break; if(j==m && strcmp(ans, b)>)
strcpy(ans, b); if(ans[]!='Z' && i==MaxLen-len)
i=, len=; ///跳出循环
} if(ans[] == 'Z')
printf("no significant commonalities\n");
else
printf("%s\n", ans);
}
return ;
}

(字符串 KMP)Blue Jeans -- POJ -- 3080:的更多相关文章

  1. Match:Blue Jeans(POJ 3080)

    DNA序列 题目大意:给你m串字符串,要你找最长的相同的连续字串 这题暴力kmp即可,注意要按字典序排序,同时,是len<3才输出no significant commonalities #in ...

  2. Blue Jeans - POJ 3080(多串的共同子串)

    题目大意:有M个串,每个串的长度都是60,查找这M个串的最长公共子串(连续的),长度不能小于3,如果同等长度的有多个输出字典序最小的那个.   分析:因为串不多,而且比较短,所致直接暴力枚举的第一个串 ...

  3. Blue Jeans POJ 3080 寻找多个串的最长相同子串

    Description The Genographic Project is a research partnership between IBM and The National Geographi ...

  4. Blue Jeans - poj 3080(后缀数组)

    大致题意: 给出n个长度为60的DNA基因(A腺嘌呤 G鸟嘌呤 T胸腺嘧啶 C胞嘧啶)序列,求出他们的最长公共子序列 使用后缀数组解决 #include<stdio.h> #include ...

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

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

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

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

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

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

  8. POJ Blue Jeans [枚举+KMP]

    传送门 F - Blue Jeans Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

  9. POJ 3080 Blue Jeans(Java暴力)

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

随机推荐

  1. docker基于commit命令创建支持ssh服务的镜像

    以centos为基础,目的使用ssh服务远程连接docker容器. 环境:宿主机centos7(宿主机ip地址为192.168.164.130),直接搜索docker的centos镜像,下载最新版本. ...

  2. WCF揭秘学习笔记(3):使用DataContractSerializer

    使用DataContractSerializer 终结点(包括地址.绑定.契约)可通过代码以编程方式添加到服务中.如: using(ServiceHost host =new ServiceHost( ...

  3. [转]Spring 之 Bean 生命周期

    Spring 容器中可以注册多个后处理器,只要它们同时实现 org.springframework.core.Ordered 接口. 下载文件 :内容来自 <精通Spring+4.x++企业应用 ...

  4. postman-3http请求

    http消息是服务器和客户端之间交换数据的方式. 有2种类型的消息: 请求:由客户端发送用来触发服务器的动作. 响应:来自服务器的应答. https://developer.mozilla.org/z ...

  5. javascript的创建对象object.create()和属性检测hasOwnPrototype()和propertyIsEnumerable()

    Object.create("参数1[,参数2]")是E5中提出的一种新的对象的创建方式. 第一个参数是要继承到新对象原型上的对象; 第二个参数是对象属性.这个参数可选,默认为fa ...

  6. logger5步走

    https://www.cnblogs.com/GGGGGGZX/p/9114378.html'''打印日志11/26/2017 10:44:21 PM bug 24 并写入文件example.log ...

  7. 软件测试——Peer Review

    一.什么是peer review peer review是一种通过作者的同行来确认缺陷和需要变更区域的检查方法.需要进行同行评审的特定产品在定义项目软件过程的时候被确定并且作为软件开发计划的一部分被安 ...

  8. HTTP代理器Fiddler(三)

    HTTP代理神器Fiddler Fiddler是一款强大Web调试工具,它能记录所有客户端和服务器的HTTP请求. Fiddler启动的时候,默认IE的代理设为了127.0.0.1:8888,而其他浏 ...

  9. C入门程序整体框架图

    0.1:概述, 从头开始介绍一门编程语言总是显得很困难,因为有许多的细节还没有介绍,很难让读者在大脑中形成一幅完整的图, 所以起步时以一个列程序向学折介绍大体的C,试图使大家对C有一个整体大概 影响. ...

  10. easyui制作进度条案例demo

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...