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