枚举长度最短的字符串的所有子串,再与其他串匹配. #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<cstdlib> #include<string> #include<cmath> #include<vector> using namespace std; ; ; ); const int in…
这个问题,需要一组字符串求最长公共子,其实灵活运用KMP高速寻求最长前缀. 请注意,意大利愿父亲:按照输出词典的顺序的规定. 另外要提醒的是:它也被用来KMP为了解决这个问题,但是很多人认为KMP使用的暴力方法,没有真正处理的细节.发挥KMP角色.而通常这些人都大喊什么暴力法能够解决本题,没错,的确暴力法是能够解决本题的,本题的数据不大,可是请不要把KMP挂上去,然后写成暴力法了.那样会误导多少后来人啊. 建议能够主要參考我的getLongestPre这个函数,看看是怎样计算最长前缀的. 怎么推…
[题目链接] http://poj.org/problem?id=3450 [题目大意] 求k个字符串的最长公共子串,如果有多个答案,则输出字典序最小的. [题解] 我们对第一个串的每一个后缀和其余所有串做kmp,取匹配最小值的最大值就是答案. [代码] #include <cstring> #include <cstdio> #include <algorithm> const int N=4050,M=210; using namespace std; int nx…
题目:http://poj.org/problem?id=2774 Long Long Message Time Limit: 4000MS   Memory Limit: 131072K Total Submissions: 36438   Accepted: 14614 Case Time Limit: 1000MS Description The little cat is majoring in physics in the capital of Byterland. A piece o…
http://blog.sina.com.cn/s/blog_74e20d8901010pwp.html我采用的是方法三. 注意:当长度相同时,取字典序最小的. #include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> /* http://blog.sina.com.cn/s/blog_74e20d8901010pwp.html 我采用的是方法三. 注意:当…
题目链接:http://poj.org/problem?id=3450 题目分类:后缀数组 题意:求n个串的最长公共字串(输出字串) //#include<bits/stdc++.h> #include<stdio.h> #include<math.h> #include<algorithm> #include<string.h> using namespace std; #define N 200005 int wa[N],wb[N],wsf[…
Blue Jeans Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20966   Accepted: 9279 Description The Genographic Project is a research partnership between IBM and The National Geographic Society that is analyzing DNA from hundreds of thousa…
题意: 给定N个字符串,寻找最长的公共字串,如果长度相同,则输出字典序最小的那个. 找其中一个字符串,枚举它的所有的字串,然后,逐个kmp比较.......相当暴力,可二分优化. #include <cstdio> #include <cmath> #include <iostream> #include <cstring> #include <string> #include <algorithm> using namespace…
题目链接:http://poj.org/problem?id=3450 题意:给定n个字符串,求n个字符串的最长公共子串,无解输出IDENTITY LOST,否则最长的公共子串.有多组解时输出字典序最小的解 思路:后缀数组的解法,我们把n个串都链接起来,中间用一些互不相同的且都没在原串中出现过的字符来分割开.然后求后缀数组.由于求的是最长公共子串,所以我们可以二分长度x,于是问题就转变成了是否有一个长度为x的子串在n个字符串中都出现过.判断的方式是:以height数组进行分组,height值不小…
题目链接:http://poj.org/problem?id=3450 题目大意:给定n个长度不超过200的字符串,n < 4000.求这些字符串的最长公共子串,若没有,则输出 “IDENTITY LOST”. 思路: 1.枚举第一个字符串的各个子串s,将s分别与其他字符串进行kmp,来找到可以取得的s的最大长度(这样就是一次枚举中所有字符串的公共子串),然后接着枚举子串s,更新这个长度,注意在长度相等时选取字典序小即可. 2.strcmp(a, b)比较a, b字符串,返回值为0则字符串相同.…