There is no any two suffix of LCP these gadgets.
First question: Enter a string s, and the longest string T causes T to appear more than once in S. The length of the output T.
1#include <algorithm>2#include <stdio.h>3#include <string.h>4 #defineN 1005 Chars[n+1];6 intN, Sa[n], rank[n], height[n];7 namespaceSabuilder {8 intCnt[n], t1[n<<1], t2[n<<1];9 voidWork () {Ten intI, k, m = -, p, *x = t1, *y =T2; Onememset (CNT,0, M *sizeof(int)); A for(i =0; I < n; ++i) ++cnt[x[i] = s[i]-'a']; - for(i =1; I < m; ++i) Cnt[i] + = cnt[i-1]; - for(i = n-1; I >=0; -i) sa[--cnt[x[i]] =i; the for(k =1; K <= N; K <<=1) { - for(i = n-k, p =0; I < n; ++i) y[p++] =i; - for(i =0; I < n; ++i)if(Sa[i] >= k) y[p++] = Sa[i]-K; -memset (CNT,0, M *sizeof(int)); + for(i =0; I < n; ++i) + +Cnt[x[y[i]]; - for(i =1; I < m; ++i) Cnt[i] + = cnt[i-1]; + for(i = n-1; I >=0; -i) sa[--cnt[x[y[i] []] =Y[i]; A Std::swap (x, y); atx[sa[0]] =0; - for(i = m =1; I < n; ++i) { -X[sa[i]] = y[sa[i]]==y[sa[i-1]]&&sa[i]+k<n&&sa[i-1]+k<n&&y[sa[i]+k]==y[sa[i-1]+K]? M-1: m++; - } - if(M > N) Break; - } inmemcpy (rank, x, n *sizeof(int)); - for(i =0, p =0; I < n; ++i)if(Rank[i]) { to if(p)--p; +K = sa[rank[i]-1]; - while(S[i+p] = = S[k+p]) + +p; theHeight[rank[i]] =p; * } $ }Panax Notoginseng } - intMain () { theRegisterintI, ans =0; + gets (s); An =strlen (s); the sabuilder::work (); +printf"%d", ans); - return 0; $}
A preliminary study on suffix Tree Group (SA)