http://www.elijahqi.win/archives/2857
题意翻译
题面描述 给定一些字符串,求出它们的最长公共子串 输入格式 输入至多
10
10 行,每行包含不超过
100000
100000 个的小写字母,表示一个字符串 输出格式 一个数,最长公共子串的长度 若不存在最长公共子串,请输出
0
0 。
题目描述
A string is finite sequence of characters over a non-empty finite set Σ.
In this problem, Σ is the set of lowercase letters.
Substring, also called factor, is a consecutive sequence of characters occurrences at least once in a string.
Now your task is a bit harder, for some given strings, find the length of the longest common substring of them.
Here common substring means a substring of two or more strings.
输入输出格式
输入格式:
The input contains at most 10 lines, each line consists of no more than 100000 lowercase letters, representing a string.
输出格式:
The length of the longest common substring. If such string doesn’t exist, print “0” instead.
输入输出样例
输入样例#1: 复制
alsdfkjfjkdsal
fdjskalajfkdsla
aaaajfaaaa
输出样例#1: 复制
2
求多个串的最长公共子串 首先针对第一个串建立sam 设mx[x]表示所有串在这个节点匹配的最长距离是多少 tmp[x]表示当前这个串和第一个串在该节点的最长匹配是多少
因为一次匹配不可能更新所有的tmp值所以我们需要在匹配之后拓扑排序之后 因为父节点肯定是当前节点的后缀所以匹配长