"BZOJ1717" [Usaco2006 dec]milk Patterns model of milk production (binary +sa)

Source: Internet
Author: User

The longest repeating substring of the repeated k times, the solution see the suffix array of the Ro great God

1 Constmaxn=100419;2  3 var4X,y,rank,sa,h,s,num,c:Array[0.. MAXN] ofLongint;5 N,time:longint;6  7 functionMax (x,y:longint): Longint;begin ifX>y ThenExit (x)ElseExit (y);End;8 functionMin (x,y:longint): Longint;begin ifX<y ThenExit (x)ElseExit (y);End;9 procedureMake ;Ten varI,j,p,tot:longint; One begin Ap:=1; -   whileP<n Do -   begin theFillchar (C,sizeof (c),0); -     fori:=1  toN-p Doy[i]:=rank[i+p]; -     fori:= n-p+1  toN Doy[i]:=0; -     fori:=1  toN DoInc (C[y[i]); +     fori:=1  toN DoInc (c[i],c[i-1]); -     fori:=1  toN Do +     begin Asa[c[y[i]]]:=i; at Dec (c[y[i]]); -     End; -Fillchar (C,sizeof (c),0); -     fori:=1  toN Dox[i]:=Rank[i]; -     fori:=1  toN DoInc (C[x[i]); -     fori:=1  toN DoInc (c[i],c[i-1]); in     fori:= NDownto 1  Do -     begin toy[sa[i]]:=C[x[sa[i]]; + Dec (c[x[sa[i]]); -     End; the     fori:=1  toN Dosa[y[i]]:=i; *tot:=1; $rank[sa[1]]:=1;Panax Notoginseng     fori:=2  toN Do -     begin the      if(x[sa[i]]<>x[sa[i-1]])or(x[sa[i]+p]<>x[sa[i-1]+P]) ThenInc (TOT); +rank[sa[i]]:=tot; A     End; thep:=p<<1; +   End; - End; $   $ proceduremakeht; - varI,j,p:longint; - begin theh[1]:=0; p:=0; -   fori:=1  toN DoWuyi   begin theP:=max (P-1,0); -    ifrank[i]=1  Thencontinue; Wuj:=sa[rank[i]-1]; -     while(i+p<=n) and(j+p<=n) and(S[i+p]=s[j+p]) DoInc (P); Abouth[rank[i]]:=p; $   End; - End; -   - procedureInit; A varI,j,tot:longint; + Ch:char; the begin - readln (n,time); $   fori:=1  toN Doreadln (S[i]); the   fori:=1  toN Dox[i]:=S[i]; theFillchar (C,sizeof (c),0); the   fori:=1  toN DoInc (C[x[i]); the   fori:=1  to  the  DoInc (c[i],c[i-1]); -   fori:=1  toN Do in   begin thesa[c[x[i]]]:=i; the Dec (c[x[i]]); About   End; therank[sa[1]]:=1; thetot:=1; the   fori:=2  toN Do +   begin -    ifx[sa[i]]<>x[sa[i-1]] ThenInc (TOT); therank[sa[i]]:=tot;Bayi   End; the Make ; the makeht; - End; -   the functionCheck (K:longint): boolean; the varI,j,x,y:longint; the begin thei:=1; -   whileI<=n Do the   begin thej:=i; the     while(j<n) and(h[j+1]&GT;=K) DoInc (J);94    ifj-i+1>=time Thenexit (true); thei:=j+1; the   End; the exit (false);98 End; About   - proceduresolve;101 varL,r,mid,ans:longint;102 begin103l:=0; R:=n>>1; ans:=0;104   whileL<=r Do the   begin106mid:= (l+r) >>1;107    ifCheck (mid) Then108     begin109L:=mid+1; theans:=mid;111     End the    Elser:=mid-1;113   End; the writeln (ans); the End; the  117 Begin118 Init;119 solve; -End.
View Code

"BZOJ1717" [Usaco2006 dec]milk Patterns model of milk production (binary +sa)

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.