http://poj.org/problem?id=3261
The length of the substring of the longest repeating k-times.
Two-point answer, become a determinant problem, according to the continuous height value is not less than the K group, if there is a set of k each height greater than K exists
#include <iostream>#include <cstdio>#include <cstring>>#include <string>#define MAXN 1000010using namespace Std;intWA[MAXN],WB[MAXN],WV[MAXN],WS[MAXN];intcmpint *r,intAintBintL) {returnR[A]==R[B]&&R[A+L]==R[B+L];} void Da (int *r,int *sa,intNint m){intI,j,p,*x=wa,*y=WB,*t; for(i=0;i<m; i++) ws[i]=0; for(i=0; i<n;i++) ws[x[i]=r[i]]++; for(i=1;i<m; i++) ws[i]+=ws[i-1]; for(i=n-1; i>=0; i--) sa[--ws[x[I]] =i; for(j=1, p=1;p <n;j*=2,m=P) { for(p=0, i=n-j;i<n;i++)y[P++]=i; for(i=0; i<n;i++)if(SA[I]>=J)y[P++]=sa[i]-j; for(i=0; i<n;i++) wv[i]=x[y[i]]; for(i=0;i<m; i++) ws[i]=0; for(i=0; i<n;i++) ws[wv[i]]++; for(i=1;i<m; i++) ws[i]+=ws[i-1]; for(i=n-1; i>=0; i--) sa[--ws[wv[i]]]=y[i]; for(t=x,x=y,y=t,p=1,x[sa[0]]=0, i=1; i<n;i++)x[SA[I]]=CMP (y, sa[i-1],sa[i],j)? p1:p + +; }return;}intSa[maxn],rank[maxn],height[maxn];void Calheight (int *r,int *sa,intN) {inti,j,k=0; for(i=1; i<=n;i++) rank[sa[i]]=i; for(i=0; i<n;height[rank[i++]]=k) for(k?k--:0, j=sa[rank[i]-1];r[i+k]==r[j+k];k++);return;}intN,k;intB[MAXN];intCheckint m){intflag=1; for(intI=1; i<=n;i++) {if(height[i]>=m) {flag++;if(flag>=k)return 1; }Elseflag=1;//At first there was no mistake, as long as one of the groups is not satisfied, this group will be obsolete}return 0;}intMain () { while(SCANF ("%d%d", &n,&k)!=-1) { for(intI=0; i<n;i++) scanf ("%d", &b[i]); b[n]=0;//cout<<"ETRH"<<endl; Da (b,sa,n+1,1000010); Calheight (B,sa,n);intans,low=0, High=n,mid; while(Low<=high) {mid= (Low+high)/2;if(Check (mid)) {ans=mid; Low=mid+1; }Elsehigh=mid-1; }printf("%d\ n", ans); }return 0;}
poj3261 longest repetition k second son string