bzoj1090: [SCOI2003]字符串折叠
同bzoj1068: [SCOI2007]压缩,一样的做法,思路,详解请看那篇文章
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <stack>
#include <deque>
#include <queue>
#include <map>
#include <vector>
#include <set>
typedef long long LL;
typedef double DB;
typedef unsigned US;
#define For(i, s, t) for(int i = (s); i <= (t); i++)
#define Ford(i, s, t) for(int i = (s); i >= (t); i--)
#define Rep(i, n) for(int i = 0; i < (n); i++)
#define Repn(i, n) for(int i = ((n) - 1); i >= 0; i--)
#define rep(i, s, t) for(int i = (s); i < (t); i++)
#define repn(i, s, t) for(int i = ((s) - 1); i >= (t); i--)
#define FU(t, c) for(__typeof((c).begin()) t = (c).begin(); t != (c).end(); t++)
#define FD(t, c) for(__typeof((c).rbegin()) t = (c).rbegin(); t != (c).rend(); t--)
#define pi (3.1415926535)
#define mk make_pair
#define sqr(x) ((x) * (x))
#define ft first
#define sd second
#define abs(x) ((x) > 0 ? (x) : (-(x)))
#define clr(c, t) (memset((c), (t), sizeof((c))))
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define Sma_let(x) (((x) >= 'a') && ((x) <= 'z'))
#define Big_let(x) (((x) >= 'A') && ((x) <= 'Z'))
#define letter(x) ((Sma_let((x))) || (Big_let((x))))
#define MIT 2147483647
#define INF 1000000000
#define MLL 1000000000000000000LL
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
using namespace std; // yzx'Rp ++
inline void SETIO(string name) {
string IN = name + ".in", OUT = name + ".out";
freopen(IN.c_str(), "r", stdin), freopen(OUT.c_str(), "w", stdout);
}
const int N = 110;
int Dp[N][N];
bool Vis[N][N];
char Dat[N];
int n;
inline void Input() {
scanf("%s", Dat + 1), n = strlen(Dat + 1);
}
inline bool Match(int S, int L, int C) {
if(L % C) return 0;
rep(i, S + C, S + L)
if(Dat[i] ^ Dat[(i - S) % C + S]) return 0;
return 1;
}
inline int Cost(int x) {
int Ret = 0;
while(x) Ret++, x /= 10;
return Ret;
}
inline int Search(int Left, int Right) {
int Len = Right - Left + 1, &Ret = Dp[Left][Right];
if(Len <= 1) return 1;
if(Vis[Left][Right]) return Ret;
Vis[Left][Right] = 1, Ret = Len;
rep(i, Left, Right)
Ret = min(Ret, Search(Left, i) + Search(i + 1, Right));
rep(i, 1, Len)
if(Match(Left, Len, i))
Ret = min(Ret, Search(Left, Left + i - 1) + 2 + Cost(Len / i));
return Ret;
}
inline void Solve() {
printf("%d\n", Search(1, n));
}
int main() {
#ifndef ONLINE_JUDGE
SETIO("1090");
#endif
Input();
Solve();
return 0;
}