字尾陣列模板

2022-08-21 07:33:10 字數 1018 閱讀 8766

字尾陣列的模板。這樣說明就非常具體了吧!

/*

* 字尾陣列模板-倍增法

* 用法:

* 1、讀取字串轉換成int陣列。長度為len。下標從0開始

* 2、在字串末尾加一字典序最小字元,一般為0,並找到最大的字元設為maxa

* 3、呼叫函式da(num,sa,len+1,maxa+1)

* 求得的sa陣列的含義: sa[i]為第i字典序字尾字串的首字母下標

* 4、呼叫函式build_height(num,sa,len)

* 求得的ranking陣列的含義: ranking[i]為首字母下標為i的字尾陣列的字典序的名次

* 求得的height陣列含義: height[i]為第i字典序字尾與第i-1字典序字尾的最長公共字首,height[1] = 0;

* h[i]=height[rank[i]]。也就是suffix(i)和在它前一名的字尾的最長公共字首。

* 注意事項:

* 轉化為數字的字串最小數值必須不小於1。假設是0的話會runtime error,請自重.......

*/#include #include #include #define inf 2*0x3f3f3f3f

using namespace std;

const int maxn = 200001; //注意陣列的大小。記得更改

int wa[maxn], wb[maxn], wv[maxn], wss[maxn];

int cmp(int *r, int a, int b, int l)

void da(int *r, int *sa, int n, int m)

return;

}int ranking[maxn], height[maxn];

void build_height(int *r, int *sa, int n)

}int sa[maxn], r[maxn];

int main()

字尾陣列 模板

char s n 陣列的長度要為兩倍的 int n n全域性變數為字元陣列的長度的 int sa n 2 high n 2 rank n 2 tmp n 2 top n 2 void makesa void lcp int main gets s int len strlen s s len get...

字尾陣列模板

過了期末了,繼續寫acm題 自己寫的字尾陣列模板。k,len,rank,sa,tmp,都要寫在外面,這樣就不用來回折騰了。也是使用倍增法來做的,得到乙個sa,儲存了字尾排在第i位的字尾的起始位置。因為空也算乙個字尾,所以函式中都是 len include include include includ...

模板 字尾陣列

include include includeusing namespace std const int max 20001 int num max int sa max rank max height max int wa max wb max wv max wd max int cmp int ...