題意:求兩個串的最長公共子串
思路:在求出height陣列之後,再把sa陣列區分出來,只要其中乙個sa[i] (s[i -1])陣列是屬於第一串,s[i - 1] (s[i])屬於第二串,那麼我們可以求得其最大值,之所以可以這樣做,是因為sa陣列已經對字串按字典序排好序了
#include
#include
#include
using
namespace std;
const
int maxn =
2e6+5;
char s1[maxn]
, s2[maxn]
, s[maxn]
;int n, p1, p2, m, p;
int tx[maxn]
, sa[maxn]
, rak[maxn]
;int height[maxn]
;struct node a[maxn]
, b[maxn]
;void
rsort()
for(
int i =
1; i <= n; i++
)for
(int i =
1; i <= m; i++
)for
(int i =
1; i <= n; i++
)for
(int i =
1; i <= m; i++
)for
(int i =
1; i <= n; i++
)for
(int i =
1; i <= m; i++
)for
(int i = n; i >=
1; i--)}
void
solve()
else
}for
(int i =
1; i <= n; i++
) m = p;
}void
ssort()
solve()
;for
(int j =
1; j <= n; j <<=1)
solve()
;if(p == n)}}
void
get_height()
int j = sa[rak[i]-1
];while
(s[i + k]
== s[j + k]
) height[rak[i]
]= k;}}
intmain()
s[++n]
='#'
;for
(int i =
1; i <= p2; i++
)ssort()
;get_height()
;int ans =0;
for(
int i =
2; i <= n; i++)}
}printf
("%d\n"
, ans)
;return0;
}
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 字尾陣列模板
求兩個字串的最長公共子串。將兩個字串連線為乙個新字串,並計算字尾陣列和高度陣列lcp。然後檢查字尾陣列中所有相鄰的字尾,其中字尾分別屬於第一和第二個字串的lcp的最大值就是答案。include include include include include include include inclu...
POJ 2774 字尾陣列基礎題
poj 2774 題意 求兩個字串的最長公共子串。總結 搞了半天還是不太理解,看著大神部落格強行敲的。而且還看到有hash 二分做的。poj 2774 include include include include include include include include include in...