[传送门:SPOJ1811&BZOJ2946] 简要题意: 给出若干个字符串,求出这些字符串的最长公共子串 题解: 后缀自动机 这两道题的区别只是在于一道给出了字符串个数,一个没给,不过也差不多(代码就贴SPOJ的,因为数据范围大一点) 首先用第一个字符串构造SAM 然后处理其他的每个串在后缀自动机的每个状态能够匹配的子串最大值 然后总的来处理所有串在这个状态能够匹配的最小值 最后将所有状态都枚举一遍,求出其中的最大值就行了 参考代码: #include<cstdio> #includ…
地址:http://www.spoj.com/problems/LCS2/ 题面: LCS2 - Longest Common Substring II no tags  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 con…
LCS2 - Longest Common Substring II 多个字符串找最长公共子串 以其中一个串建\(SAM\),然后用其他串一个个去匹配,每次的匹配方式和两个串找\(LCS\)一样,就是要记录\(SAM\)的每个状态和当前匹配串匹配的最大值\(maxx\),这个在匹配完一个串之后需要通过\(parent\)树上传最大匹配值,同时要更新一个最小值\(minn\),来表示每个节点和当前已经匹配过的所有串能匹配上的最大值,这个需要每次匹配一个串之后和当前节点的\(maxx\)取\(min…
LCS2 - Longest Common Substring II 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 leas…
[SP1812]LCS2 - Longest Common Substring II 题面 洛谷 题解 你首先得会做这题. 然后就其实就很简单了, 你在每一个状态\(i\)打一个标记\(f[i]\)表示状态\(i\)能匹配到最长的子串长度, 显然\(f[i]\)可以上传给\(f[i.fa]\). 然后去每个串和第\(1\)个串\(f\)的最小值的最大值即可. 代码 #include <iostream> #include <cstdio> #include <cstdlib&…
LCS2 - Longest Common Substring II no tags  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 occurrence…
spoj 1812 LCS2 - Longest Common Substring II 题意: 给出最多n个字符串A[1], ..., A[n], 求这n个字符串的最长公共子串. 限制: 1 <= n <= 10 |A[i]| <= 1e5 思路: 和spoj 1811 LCS几乎相同的做法 把当中一个A建后缀自己主动机 考虑一个状态s, 假设A之外的其它串对它的匹配长度各自是a[1], a[2], ..., a[n - 1], 那么min(a[1], a[2], ..., a[n -…
A string is finite sequence of characters over a non-empty finite set \(\sum\). In this problem, \(\sum\) is the set of lowercase letters. Substring, also called factor, is a consecutive sequence of characters occurrences at least once in a string. N…
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 i…
对于本题这样的多字符串的子串匹配问题,其实用广义后缀自动机就可以很好的解决,感觉会比普通的后缀自动机做法方便一些. 首先记录出每个节点被多少个字符串更新,也就是记录每个节点有多少个字符串能到达它,可以通过在\(Parent\)树上求子树和处理出. 若所有字符串都能到达一个节点,也就是该节点所对应的串为所有字符串的子串,那么该节点是一个合法的转移状态. 那么就可以直接拿这些字符串中的任意一个字符串在自动机上匹配,就像LCS - Longest Common Substring一样,只向合法状态转移…