Topic: Given a string, in accordance with the problem of the compression method to the shortest possible compression to how long
Interval DP Order F[i][j] Indicates how long a string within the [I,j] interval can be compressed to
Normal interval dp:f[i][j]=min{f[i][k]+f[k+1][j]} (i<=k<=j-1)
In addition, if the string is compressed, then we can enumerate the loop section, using hash to determine
If k is a cyclic section, then there is f[i][j]=min (f[i][j],f[i][i+k-1]+digit[len/k]+2)
Where len=j-i+1,digit represents the length of a number under a decimal
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define M 110# Define BASE 151using namespace Std;typedef unsigned long long ll;int N,digit[m],f[m][m];char s[m];ll hash[m],power[m];voi D pretreatment () {int i;for (i=1;i<=n;i++) digit[i]=digit[i/10]+1;for (power[0]=1,i=1;i<=n;i++) power[i]=power[ I-1]*base;for (i=1;i<=n;i++) hash[i]=hash[i-1]*base+s[i];} int main () {int i,j,k,len;scanf ("%s", s+1); N=strlen (s+1); Pretreatment (); memset (f,0x3f,sizeof f); for (i=1;i<=n;i++) f[i][i]=1;for (len=2;len<=n;len++) for (I=1; (j=i+ len-1) <=n;i++) {for (k=i;k<j;k++) f[i][j]=min (F[i][j],f[i][k]+f[k+1][j]), for (k=1;k<n;k++) if (len%k==0) {ll Hash1=hash[j-k]-hash[i-1]*power[len-k];ll hash2=hash[j]-hash[i+k-1]*power[len-k];if (HASH1!=HASH2) continue;f[i][ J]=min (f[i][j],f[i][i+k-1]+digit[len/k]+2);}} Cout<<f[1][n]<<endl;return 0;}
Bzoj 1090 SCOI2003 string folding dynamic planning +hash