SAM
- SAM
- 5. 初级应用
- 5.1 静态本质不同子串个数
- 5.2 字符串匹配
- 5.3 关于子串出现次数
- 5.4 动态添加时本质不同子串个数
SAM
5. 初级应用
- 记 l o n g e s t ( x ) longest(x) longest(x) 为点 x x x 代表子串集合中最长串的长度。
- 记 s h o r t e s t ( x ) shortest(x) shortest(x) 为点 x x x 代表子串集合中最短串的长度。
- 记 s z x sz_x szx 为点 x x x 代表的 e d p edp edp 的大小。
- 可能用 l e n ( x ) , l e n x , x . l e n len(x),len_x,x.len len(x),lenx,x.len 表示点 x x x 所代表子串集合中最长串的长度, l i n k link link 等也是这样。
- 其他定义和 SAM详解1一样。
5.1 静态本质不同子串个数
在 parent tree 上,每个节点的 e d p edp edp 集合不同,即代表的子串不同。
则显然有 a n s = ∑ i = 1 l o n g e s t ( i ) − s h o r t e s t ( i ) + 1 ans=\sum_{i=1}longest(i)-shortest(i)+1 ans=∑i=1longest(i)−shortest(i)+1
然后有 s h o r t e s t ( i ) = l o n g e s t ( f a i ) + 1 shortest(i)=longest(fa_i)+1 shortest(i)=longest(fai)+1,其中 f a i fa_i fai 为 i i i 的父节点。
替换,则有 a n s = ∑ i = 1 l o n g e s t ( i ) − l o n g e s t ( f a i ) ans=\sum_{i=1}longest(i)-longest(fa_i) ans=∑i=1longest(i)−longest(fai),或者 a n s = ∑ i = 1 l e n ( i ) − l e n ( l i n k ( i ) ) ans=\sum_{i=1}len(i)-len(link(i)) ans