字尾陣列 模板

2021-06-18 02:24:46 字數 601 閱讀 6655

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]='$';

gets(s+len+1);

makesa();

lcp();

int ans=0;

repf(i,1,n-1)//到n-1就行了,因為n是在len的長度上加2,n也行,其實自己就很迷糊的

// if((len-sa[i])*(len-sa[i-1])<0)

if((sa[i]len) || (sa[i]>len && sa[i-1]

sa[i]代表的是排第i的字元的位置.rank[i]代表的是第i個排第幾的

high陣列:定義high[i]=suffix(sa[i-1]) suffix(sa[i]) 的最長公共字首,也就是排名相鄰的兩個字尾的最長公共字首

字尾陣列模板

過了期末了,繼續寫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 ...

字尾陣列模板

字尾陣列的模板,這樣說明就很詳細了吧!字尾陣列模板 倍增法 使用方法 1 讀取字串轉換成int陣列,長度為len,下標從0開始 2 在字串末尾加一字典序最小字元,一般為0,並找到最大的字元設為maxa 3 呼叫函式da num,sa,len 1,maxa 1 求得的sa陣列的含義 sa i 為第i字...