[题目通道]([SCOI2003] 字符串折叠 - 洛谷)
cpp
#include <bits/stdc++.h>
#define int long long
#define fast register int
using namespace std;
char s[110];
int n,m[110],f[110][110];
bool check(char s[],int n,int len){
for (fast i=len;i<n;i++){
if(s[i]!=s[i%len])return false;
}
return true;
}
signed main(){
scanf("%s",s);
n=strlen(s);
for (fast i=1;i<=9;i++){
m[i]=1;
}
for (fast i=10;i<=99;i++){
m[i]=2;
}
m[100]=3;
memset(f,0x3f,sizeof(f));
for (fast i=0;i<n;i++){
f[i][i]=1;
}
for (fast l=2;l<=n;l++){
for (fast i=0,j=i+l-1;j<n;i++,j++){
for (fast k=i;k<j;k++){
f[i][j]=min(f[i][j],f[i][k]+f[k+1][j]);
}
for (fast k=i;k<j;k++){
int len=k-i+1;
if (l%len!=0) {
continue;
}
if (check(s+i,l,len)){
f[i][j]=min(f[i][j],f[i][k]+2+m[l/len]);
}
}
}
}
printf("%d",f[0][n-1]);
return 0;
}