【HDOJ】1403 Longest Common Substring】的更多相关文章

后缀数组2倍增可解. #include <cstdio> #include <cstring> #include <cstdlib> #define MAXM 28 #define MAXN 100010 ]; ]; ]; ]; char s[MAXN]; ], sa[MAXN*]; ], rank[MAXN*]; bool cmp(int *r, int a, int b, int l) { return r[a]==r[b] && r[a+l]==r…
[SP1812]LCS2 - Longest Common Substring II 题面 洛谷 题解 你首先得会做这题. 然后就其实就很简单了, 你在每一个状态\(i\)打一个标记\(f[i]\)表示状态\(i\)能匹配到最长的子串长度, 显然\(f[i]\)可以上传给\(f[i.fa]\). 然后去每个串和第\(1\)个串\(f\)的最小值的最大值即可. 代码 #include <iostream> #include <cstdio> #include <cstdlib&…
[SP1811]LCS - Longest Common Substring 题面 洛谷 题解 建好后缀自动机后从初始状态沿着现在的边匹配, 如果失配则跳它的后缀链接,因为你跳后缀链接到达的\(Endpos\)集合中的串肯定是当前\(Endpos\)中的后缀,所以这么做是对的. 你感性理解一下,这样显然是最大的是吧... 具体实现看代码: 代码 #include <iostream> #include <cstdio> #include <cstdlib> #inclu…
http://www.spoj.com/problems/LCS2/ 发现了我原来对sam的理解的一个坑233 本题容易看出就是将所有匹配长度记录在状态上然后取min后再对所有状态取max. 但是不要忘记了一点:更新parent树的祖先. 为什么呢?首先如果子树被匹配过了,那么长度一定大于任意祖先匹配的长度(甚至有些祖先匹配长度为0!为什么呢,因为我们在匹配的过程中,只是找到一个子串,可能还遗漏了祖先没有匹配到,这样导致了祖先的记录值为0,那么在对对应状态取min的时候会取到0,这样就wa了.而…
传送门 洛谷 Solution 考虑他要求的是最长公共子串对吧,那么我们对于一个串建后缀自动机,另一个串在后缀自动机上面跑就是了. 复杂度\(O(n+m)\)的,很棒! 代码实现 代码戳这里…
题目链接 题意翻译 输入2 个长度不大于250000的字符串,输出这2 个字符串的最长公共子串.如果没有公共子串则输出0 . 思路 求两个串的最长公共子串 代码 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define maxn 500010 using namespace std; int n, n1, n2; char s1[maxn], s2[ma…
题目链接 对第一个串建出\(SAM\),然后用第二个串去匹配. 如果能往下走就往下走,不能的话就跳parent tree的父亲,直到能走为止.如果跳到\(0\)了还是不能走,重新匹配. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int MAXN = 1000010; struct SAM{ int ch[26]; int len, fa; }s…
http://acm.hdu.edu.cn/showproblem.php?pid=1403 Longest Common Substring Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3068    Accepted Submission(s): 1087 Problem Description Given two string…
先上题目: Longest Common Substring Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4010    Accepted Submission(s): 1510 Problem Description Given two strings, you have to tell the length of the Long…
Description Given two strings, you have to tell the length of the Longest Common Substring of them. For example:str1 = bananastr2 = cianaic So the Longest Common Substring is "ana", and the length is 3. Input The input contains several test case…