You can do this first before you do it http://www.lydsy.com/JudgeOnline/problem.php?id=1090
I was going to do an interval DP.
However too weak to quickly understand how to use the traditional interval DP (interval merge) to write this problem
So first with their yy method of comparison of water to do it again (in fact, the simulation of the test instructions in the compression operation)
Using f[i][j] means that the original string is now processed with the first bit and the minimum cost of the buffer string length J
So F[i][j] can be transferred from these three situations.
F[i-1][j-1]+1 (fill in the original letter)
F[i-j/2][j/2]+1 (fill r,j for even)
F[i][k]+1 (fill m,j=0)
So you can go through the water first (note that a relatively coarse upper bound of J is i*2)
#include <bits/stdc++.h>using namespacestd;Chars[ -];intf[ -][ the];intN,ans;BOOLCheckintLintR) { intlen=r-l+1; for(inti=l;i<=r;++i)if(s[i]!=s[i-Len]) return 0; return 1;}intMain () {memset (F,0x3f,sizeof(f)); scanf ("%s", &s[1]); N=strlen (&s[1]); f[0][0]=0; for(intI=1; i<=n;++i) { for(intJ=max ((I-1)*2,1); j;--j) {F[i][j]=f[i-1][j-1]+1; if((j&1)==0&&check (i-j/2+1, i)) F[I][J]=min (f[i][j],f[i-j/2][j/2]+1); f[i][0]=min (f[i][0],f[i][j]+1); }} ans=f[n][0]; for(inti=n*2; i;--i) ans=min (ans,f[n][i]); printf ("%d\n", ans); return 0;}
Dig this hole first, and then we'll use the traditional interval DP method to pits
Bzoj 1068: [SCOI2007] Compression