poj2774(字尾陣列 字串hash)

2021-07-16 06:53:23 字數 666 閱讀 4255

求兩個串的最長公共子串

將兩個串連起來,求字尾陣列,sa中相鄰兩個字尾如果不屬於同乙個模版,則用這個height更新答案,他們的最長公共字首更新答案

#include#include#include#include#include#include#define max(x,y) (x)>(y)?(x):(y)

using namespace std;

const int n=1000005;

int n,s[n],c[n],t1[n],t2[n],sa[n],height[n],rank[n],len1,len2;

char s1[n],s2[n];

void build_sa()

}void build_height()

/********************************************/

char s1[n],s2[n];

int len1,len2;

ll hs1[n],hs2[n],po[n];

ll a[n];

bool pan(int mid)

return false;

}int main()

printf("%d",ans);

return 0;

}

poj 2774 字尾陣列

include include define debug ifdef debug define debug printf va args else define debug endif define maxn 200004 define min a,b a b a b int wx maxn wy ...

POJ 2774 字尾陣列

題意 求兩個串的最長公共子串 思路 在求出height陣列之後,再把sa陣列區分出來,只要其中乙個sa i s i 1 陣列是屬於第一串,s i 1 s i 屬於第二串,那麼我們可以求得其最大值,之所以可以這樣做,是因為sa陣列已經對字串按字典序排好序了 include include includ...

poj 2774 字尾陣列模板

求兩個字串的最長公共子串。將兩個字串連線為乙個新字串,並計算字尾陣列和高度陣列lcp。然後檢查字尾陣列中所有相鄰的字尾,其中字尾分別屬於第一和第二個字串的lcp的最大值就是答案。include include include include include include include inclu...