bzoj1068: [SCOI2007] Compression

Source: Internet
Author: User

Interval DP.

The bool T indicates whether the range can contain m.

If it cannot contain m, there is res=min{f[l][i][0]+r-i}. (I<r) (The minimum value of the string length equals the minimum value after the previous string compression and does not compress the length of the subsequent string).

If the string length is even, and the first half is equal to the second half, there is F[l][r][t]=min (f[l][(l+r) >>1][t]+1) (the second half is replaced with 1 R).

If t=1, except for the two above and Res=min{f[l][i][1]+1+f[i+1][r][1]}.

The State and 3 state transfer equations are more difficult to think of. This is largely due to the fact that the interval DP is not familiar.

#include <cstdio>#include<algorithm>#include<cstring>using namespacestd;Const intMAXN = -+Ten;intf[maxn][maxn][2];Chars[ -];BOOLSame (intLintr) {intn=r-l+1; if(n%2)return 0; intMid= (l+r) >>1;  for(intI=l,j=mid+1; i<=mid;i++,j++)if(S[i]!=s[j])return 0; return 1;}intdpintLintRBOOLt) {if(L==R)return 1; if(F[l][r][t])returnF[l][r][t]; int&res=F[l][r][t]; Res=r-l+1; if(t) for(inti=l;i<r;i++) Res=min (RES,DP (L,i,1) +DP (i+1R1)+1);  for(inti=l;i<r;i++) Res=min (RES,DP (l,i,t) +r-i); if(Same (L,r)) Res=min (RES,DP (L, (l+r) >>1,0)+1); returnRes;}intMain () {scanf ("%s", s+1); printf ("%d\n", DP (1, strlen (s+1),1)); return 0;}

bzoj1068: [SCOI2007] Compression

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.