poj 1743 差分 字尾陣列

2022-08-12 12:12:12 字數 1070 閱讀 6495

首先,musical theme只與前後位置的增減關係有關,而與絕對的數值無關,因此想到做一次差分。

然後對於差分後的陣列,找到最長的出現兩次(或兩次以上)的乙個子串即可。這個如果說兩個子串可以交叉的話就好做了,直接取height的最大值即可,但是題目要求不能交叉,前幾天一位師兄講課剛講了,可以用二分做。對於乙個指定長度l,判斷它是否可行,就用這個l去劃分height陣列,對於每個部分的分別看看最遠的兩個是否沒有交叉就可以了。

#include#include

#include

using

namespace

std;

const

int maxn=20005

;#define f(x) ((x)/3+((x)%3==1?0:tb))

#define g(x) ((x)int wa[maxn*3],wb[maxn*3],wv[maxn*3],wss[maxn*3

];int c0(int *r,int a,int

b)int c12(int k,int *r,int a,int

b)void sort(int *r,int *a,int *b,int n,int

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

m)void da(int str,int sa,int rank,int height,int n,intm)}

int a[maxn*3

];int ra[maxn*3],height[maxn*3],sa[maxn*3

];bool

xk[maxn];

const

int inf=0x3f3f3f3f

;bool check(int k,int

n)

else

}return

false;}

int solve(int

n)//

return l;

if (l<4) return0;

return l+1;}

intmain()

return0;

}

poj 1743 字尾陣列

字尾陣列,求不可重疊最長重複字串。include include include include include include define maxd 21000 using namespace std int r maxd rank maxd height maxd int sa maxd wa...

POJ 1743 字尾陣列

這裡有一篇 總結了很多字尾陣列的用法,是 字尾陣列 處理字串的有力工具 羅穗騫 裡面又很多關於這個字尾陣列的具體用法,其中就包括這個不可重疊最長重複子串 這個題的意思就是求解不可重疊最長重複子串,但是這裡有乙個問題,他的串中也可以是相似的 每個數之間的差值相同的 那麼我們就可以利用這個差相同的性質,...

POJ 1743(字尾陣列)

給定乙個字串,求最長重複子串,這兩個子串不能重疊。演算法分析 這題比上一題稍複雜一點。先二分答案,把題目變成判定性問題 判斷是否 存在兩個長度為 k 的子串是相同的,且不重疊。解決這個問題的關鍵還是利用height 陣列。把排序後的字尾分成若干組,其中每組的字尾之間的 height 值都不小於 k。...