状态定义是(l,r,t)表示l到r的字串,t表示中间能否放M,注意最开始有个M
const int N = 60;
char Dat[N];
int Dp[N][N][2];
bool Vis[N][N][2];
inline void Input() {
scanf("%s", Dat + 1);
}
inline bool Match(int A, int B) {
int Len = B - A;
Rep(i, Len)
if(Dat[A + i] ^ Dat[B + i]) return 0;
return 1;
}
inline int Search(int L, int R, bool Able) {
if(Vis[L][R][Able]) return Dp[L][R][Able];
if(L == R) return 1;
Vis[L][R][Able] = 1;
int Ret = R - L + 1, Len = R - L + 1;
For(i, L, R - 1) {
if(Able) Ret = min(Ret, Search(L, i, 1) + 1 + Search(i + 1, R, 1));
Ret = min(Ret, Search(L, i, Able) + R - i);
}
if(Len % 2 == 0 && Match(L, L + (Len >> 1))) Ret = min(Ret, Search(L, L + (Len >> 1) - 1, 0) + 1);
return Dp[L][R][Able] = Ret;
}
inline void Solve() {
printf("%d\n", Search(1, strlen(Dat + 1), 1));
}
int main() {
#ifndef ONLINE_JUDGE
SETIO("1068");
#endif
Input();
Solve();
return 0;
}