字尾陣列 LCP(最長公共字首)

2021-08-09 09:19:26 字數 476 閱讀 5580

sa : sa陣列儲存的是乙個1-n的全排列,儲存的是:

將所有字尾按字典序排序後,串在原串中的位置。

即有suffix(sa[i]) < suffix(sa[i+1])

rank : rank陣列儲存的是 suffix(i)在所有字尾中按字典序排序的「名次」。

總結:字尾陣列是「排第幾的是誰?」,名次陣列是「你排第幾?」

lcp(i,j):suffix(sa[i])與suffix[sa[j]]的最長公共字首長度,即排序後的字尾中第i個和第j個的最長公共字首長度。

lcp(i,j) = min i < k <= j;

height:height[i]=suffix(sa[i-1])和suffix(sa[i])的最長公共字首,也就是排名相鄰的兩個字尾的最長公共字首的長度 。

輔助陣列h:h[i] = height[rank[i]],也就是suffix(i)和排序後在它前一名的字尾的最長公共字首的長度。

字尾陣列之最長公共字首

include define maxn 100 int main s maxn s串可以看成abcbc int i,j,k 0 for i 0 i 5 i rank sa i i for i 0 i 5 i if k k j sa rank i 1 當rank k 不等於0的時候,rank i 1計...

Hash求LCP最長公共字首

include includeusing namespace std typedef unsigned long long ull const int maxl 40000,base 233333333 base亂取 反正看rp int m,len,where,id maxl 5 char s ma...

hdu4691(字尾陣列求最長公共字首)

學習鏈結 題意 題目的本質就是求輸入的相鄰的兩個串的最長公共字串,有sa來解求得height陣列,然後用rmq演算法查詢。解題思路 sa模板 st模板 如下 include include include include include include define n 100005 define ...