Common Substrings \[ Time Limit: 5000 ms\quad Memory Limit: 65536 kB \] 题意 给出两个字符串,要求两个字符串公共子串长度不小于 \(k\) 的对数. 思路 对 \(S\) 串构建后缀自动机,然后利用 \(v \in u'son\),\(dp[u] += dp[v]\) 求出每个节点的 \(endpos\) 大小. 用 \(T\) 串在自动机上跑最长公共连续子串,假设现在在 \(T\) 串上匹配的最长部分是 \(t\),停在自…
POJ 3415 Common Substrings Problem : 给两个串S.T (len <= 10^5), 询问两个串有多少个长度大于等于k的子串(位置不同也算). Solution :最开始的想法是将S串和T串先后插入后缀自动机,统计出每个节点对应串的出现次数,不过这种做法被卡空间了. 第二种想法是只将S串插入后缀自动机,建立后缀树,统计出每个节点对应串的出现次数,在统计出每个节点的所有父亲节点的出现次数之和.之后将T串在后缀自动机上进行匹配,假设当前T串在p节点匹配成功,且匹配成…
题意: 给定两个字符串A 和 B, 求长度不小于 k 的公共子串的个数(可以相同) 分两部分求和sa[i-1] > len1  sa[i] < len1  和  sa[i-1] < len1   sa[i] > len1 #include <iostream> #include <cstdio> #include <sstream> #include <cstring> #include <map> #include &l…
[SPOJ]Longest Common Substring II (后缀自动机) 题面 Vjudge 题意:求若干个串的最长公共子串 题解 对于某一个串构建\(SAM\) 每个串依次进行匹配 同时记录\(f[i]\)表示走到了\(i\)节点 能够匹配上的最长公共子串的长度 当然,每个串的\(f[i]\)可以更新\(f[i.parent]\) 所以需要拓扑排序 对于每个串求出每个节点的最长匹配 然后对他们取\(min\),表示某个节点大家都能匹配的最长长度 最后对于所有点的值都取个\(max\)…
题目链接:http://poj.org/problem?id=3415 题意:给定2个串[A串和B串],求两个串公共子串长度大于等于k的个数. 思路:首先是两个字符串的问题.所以想用一个'#'把两个字符串拼接起来.求后缀数组. 然后按照k把height数组分组.大于等于k的为一组,然后就是统计每组的贡献.对于每一组的贡献即是组内所有A串的后缀和B串的后缀的lcp值,即为val.那么val对于答案的贡献为(val-k+1).如果我们暴力每组的AB串后缀的组合.时间复杂度是O(n^2).不能满足要求…
Given a string, we need to find the total number of its distinct substrings. Input \(T-\) number of test cases. \(T<=20\); Each test case consists of one string, whose length is \(<=1000\) Output For each test case output one number saying the numbe…
Common Substrings Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 11469   Accepted: 3796 Description A substring of a string T is defined as: T(i, k)=TiTi+1...Ti+k-1, 1≤i≤i+k-1≤|T|. Given two strings A, B and one integer K, we define S,…
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…
POJ 3518 Boring Problem : 给一个串S,询问串S有多个子串出现至少两次且位置不重叠. Solution : 对S串建立后缀自动机,再建立后缀树,dfs一遍统计处每个结点的子树中最长节点max和最短节点min.枚举一遍后缀自动机的节点,那么对于其对应后缀的长度要求为小于等于max - min. #include <iostream> #include <algorithm> using namespace std; const int N = 1000008;…