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=1?longest(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=1?longest(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