This problem and UVA 122,061-like, for at least repeat the longest string of K-times.
First, the length of the longest string, Len, and then segment the height array with Len as the boundary, if there is a section that contains more than k suffixes, it meets the requirements.
1#include <cstdio>2#include <cstring>3#include <algorithm>4 using namespacestd;5 6 Const intMAXN =20000+Ten;7 Const intMAXM =1000000+Ten;8 9 intS[MAXN];Ten intSA[MAXN], HEIGHT[MAXN], RANK[MAXN]; One intT[MAXN], T2[MAXN], C[MAXM]; A intN, K; - - voidBuild_sa (intm) the { - intI, *x = t, *y =T2; - for(i =0; I < m; i++) C[i] =0; - for(i =0; I < n; i++) C[x[i] = s[i]]++; + for(i =1; I < m; i++) C[i] + = c[i-1]; - for(i = n-1; I >=0; i--) Sa[--c[x[i]] =i; + for(intK =1; K <= N; K <<=1) A { at intp =0; - for(i = n-k; i < n; i++) y[p++] =i; - for(i =0; I < n; i++)if(Sa[i] >= k) y[p++] = Sa[i]-K; - for(i =0; I < m; i++) C[i] =0; - for(i =0; I < n; i++) c[x[y[i]]]++; - for(i =1; I < m; i++) C[i] + = c[i-1]; in for(i = n-1; I >=0; i--) sa[--c[x[y[i] []] =Y[i]; - swap (x, y); top =1; x[sa[0]] =0; + for(i =1; I < n; i++) -X[sa[i]] = y[sa[i]]==y[sa[i-1]] && y[sa[i]+k]==y[sa[i-1]+K]? P-1: p++; the if(P >= N) Break; *m =p; $ }Panax Notoginseng } - the voidbuild_height () + { A intI, j, k =0; the for(i =0; I < n; i++) Rank[sa[i] =i; + for(i =0; I < n; i++) - { $ if(k) k--; $j = Sa[rank[i]-1]; - while(S[i + K] = = S[j + K]) k++; -Height[rank[i]] =K; the } - }Wuyi the BOOLOkintlen) - { Wu intCNT =0; - for(inti =0; I < n; i++) About { $ if(i = =0|| Height[i] < len) cnt =0; - if(++cnt >= k)return true; - } - return false; A } + the intMain () - { $ //freopen ("In.txt", "R", stdin); the thescanf"%d%d", &n, &k); the for(inti =0; I < n; i++) the { -scanf"%d", &s[i]); ins[i]++; the } theS[n] =0; AboutBuild_sa (1000002); the build_height (); the the intL =1, R =N; + while(L <R) - { the intM = (L + R +1) /2;Bayi if(OK (M)) L =M; the ElseR = M-1; the } - -printf"%d\n", L); the the return 0; the}code June
POJ 3261 (suffix array dichotomy) Milk Patterns