POJ3261 Milk Patterns (binary + suffix array)

Source: Internet
Author: User

The topic asks for the longest repetition K-th overlapping substrings.

and POJ1743.

    1. Two-minute enumeration of ANS determines whether it is established
    2. Height group, if the number of groups greater than or equal to ans is greater than or equal to k-1, this ans is feasible
1#include <cstdio>2#include <cstring>3#include <algorithm>4 using namespacestd;5 #defineMAXN 10000016 7 intWA[MAXN],WB[MAXN],WV[MAXN],WS[MAXN];8 intcmpint*r,intAintBintl) {9     returnR[A]==R[B] && r[a+l]==r[b+l];Ten } One intSA[MAXN],RANK[MAXN],HEIGHT[MAXN]; A voidSA (int*r,intNintm) { -     int*x=wa,*y=WB; -  the      for(intI=0; i<m; ++i) ws[i]=0; -      for(intI=0; i<n; ++i) ++ws[x[i]=R[i]]; -      for(intI=1; i<m; ++i) ws[i]+=ws[i-1]; -      for(inti=n-1; i>=0; -I.) sa[--ws[x[i]]]=i; +  -     intp=1; +      for(intj=1; p<n; j<<=1, m=p) { Ap=0; at          for(intI=n-j; i<n; ++i) y[p++]=i; -          for(intI=0; i<n; ++i)if(SA[I]&GT;=J) y[p++]=sa[i]-J; -          for(intI=0; i<n; ++i) wv[i]=X[y[i]]; -          for(intI=0; i<m; ++i) ws[i]=0; -          for(intI=0; i<n; ++i) + +Ws[wv[i]]; -          for(intI=1; i<m; ++i) ws[i]+=ws[i-1]; in          for(inti=n-1; i>=0; -I.) sa[--ws[wv[i]]]=Y[i]; -Swap (x, y); x[sa[0]]=0; p=1; to          for(intI=1; i<n; ++i) x[sa[i]]=cmp (y,sa[i-1],sa[i],j)? p1:p + +; +     } -  the      for(intI=1; i<n; ++i) rank[sa[i]]=i; *     intk=0; $      for(intI=0; i<n-1; height[rank[i++]]=k) {Panax Notoginseng         if(k)--K; -          for(intj=sa[rank[i]-1]; R[I+K]==R[J+K]; ++k); the     } + } A  the intN,K,A[MAXN]; + BOOLisOKintLen) { -     intCnt=0; $     BOOLflag=0; $      for(intI=2; i<=n; ++i) { -         if(height[i]>=Len) { -             if(flag) { the++CNT; -                 if(cnt+1&GT;=K)return 1;Wuyi}Else{ theflag=1; -Cnt=1; Wu                 if(cnt+1&GT;=K)return 1; -             } About}Else{ $flag=0; -Cnt=0; -         } -     } A     return 0; + } the intMain () { -     intmx=0; $scanf"%d%d",&n,&k); the      for(intI=0; i<n; ++i) { thescanf"%d", A +i); theMx=max (mx,++a[i]); the     } -a[n]=0; inSA (a,n+1, mx+1); the     intL=0, r=N; the      while(l<R) { About         intmid=l+r+1>>1; the         if(isOK (mid)) l=mid; the         Elser=mid-1; the     } +printf"%d", L); -     return 0; the}

POJ3261 Milk Patterns (binary + suffix array)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.