后缀数组
azheng51714
欢迎加入 老生畅坛 微信公众号
展开
-
后缀数组 倍增模版+D3C模版
int wa[maxn],wb[maxn],wv[maxn],ws[maxn];int cmp(int *r,int a,int b,int l){return r[a]==r[b]&&r[a+l]==r[b+l];}void da(int *r,int *sa,int n,int m){ int i,j,p,*x=wa,*y=wb,*t; for(i=0;原创 2013-01-23 16:24:55 · 458 阅读 · 0 评论 -
hdu 4436 后缀数组
某牛的解题思路:题目大意给出n个字符串,求出所有字符串中出现的不同的整数和mod2012的值(即出现多次算一次)找出所有的子串然后出重,先用分隔符符将所有串都连接起来,然后跑后缀数组,接下来就是计算。从计算第i个后缀的时候,显然从i开始的字符串长度要在i+height[rank[i]]~第i个串的结束位置,因为前面的必然重复了,但也不能超过结束位置。计算的话就是维护一个部分原创 2013-01-25 15:58:48 · 1368 阅读 · 0 评论 -
hdu 3415 后缀数组 长度不小于 k 的公共子串的个数
///长度不小于 k 的公共子串的个数/* 单调队列优化 1 aa 1 2 ab 1 3 abc 2 4 ad 1*/#include #include #include #include using namespace std;const int MAXN=2222222;char s1[MAXN],s2[MAXN];int r[MAXN],lcp[MAXN]原创 2013-01-25 11:28:14 · 551 阅读 · 0 评论 -
poj 3974 史上最NB 求最长回文子串 O(N) Manacher算法
/* Manacher算法--O(n)回文子串算法 OTL(好牛B的算法啊) O(n)求最长回文子串 p[i]-1为新串以str[i]为中心的最大回文长度,以#为中心则回文串长度为偶数,否则为奇数*/#include #include #include #include #define Maxn 1000100using namespace std;char原创 2013-01-24 14:38:12 · 1042 阅读 · 0 评论 -
poj 1743 字符串 后缀数组 不可重叠最长重复子串
题意:有N个音符的序列来表示一首乐曲,每个音符都是1..88范围内的整数,现在要找一个重复的主题。“主题”是整个音符序列的一个子串,它需要满足如下条件: 1.长度至少为5个音符。 2.在乐曲中重复出现。(可能经过转调,“转调”的意思是主题序列中每个音符都被加上或减去了同一个整数值) 3.重复出现的同一主题不能有公共部分。首先看到转调,这很重要,一个序列原创 2013-01-24 11:20:05 · 475 阅读 · 0 评论 -
poj 2406 D3C 算法 后缀数组 连续重复子串
#include #include #include #include using namespace std;const int MAXN=10000005;int r[MAXN],lcp[MAXN];char s[MAXN];#define F(x) ((x)/3+((x)%3==1?0:tb))#define G(x) ((x)<tb?(x)*3+1:((x)-tb)*3原创 2013-01-24 16:22:00 · 657 阅读 · 0 评论 -
spoj 694 OR 705 不相同的子串的个数
每个子串一定是某个后缀的前缀,那么原问题等价于求所有后缀之间的不相同 的 前 缀 的 个 数 。 如 果 所 有 的 后 缀 按 照 suffix(sa[1]), suffix(sa[2]),suffix(sa[3]), ...... ,suffix(sa[n])的顺序计算,不难发现,对于每一次新加进来的 后缀 suffix(sa[k]), 它将产生 n-sa[k]+1 个新 的前原创 2013-01-24 13:51:25 · 454 阅读 · 0 评论 -
poj 2774 最长公共子串 后缀数组
#include #include #include #include using namespace std;const int MAXN=2222222;char s1[MAXN],s2[MAXN];int r[MAXN],lcp[MAXN];int wa[MAXN], wb[MAXN], wv[MAXN], tmp[MAXN],a[MAXN];;int sa[MAXN];原创 2013-01-24 20:55:37 · 404 阅读 · 0 评论 -
poj 3261 后缀数组 Or KMP 可重叠的 k 次最长重复子串
///题意: 求一个串至少出现k次的最长重复子串的长度,可重叠#include #include #include #include #include #include #define MAXN 22222using namespace std;int r[MAXN];int wa[MAXN], wb[MAXN], wv[MAXN], tmp[MAXN],a[MAXN];;i原创 2013-01-24 12:16:17 · 728 阅读 · 0 评论 -
poj 3882 后缀数组 求一个串至少出现k次的最长重复子串的长度
///题意: 求一个串至少出现k次的最长重复子串的长度,可重叠#include #include #include #include #include #include #define MAXN 42222using namespace std;int max(int a,int b){ return a>=b?a:b;}int r[MAXN];char s[MAXN]原创 2013-05-24 13:26:01 · 787 阅读 · 0 评论