You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
488 B

#include <bits/stdc++.h>
using namespace std;
const int N = 110;
const int INF = 0x3f3f3f3f;
string s;
int f[N][N];
int dfs(int l, int r) {
if (l == r) return 1;
if (f[l][r]) return f[l][r];
int res = INF;
if (s[l] == s[r]) return dfs(l, r - 1);
for (int i = l; i < r; i++)
res = min(res, dfs(l, i) + dfs(i + 1, r));
return f[l][r] = res;
}
int main() {
cin >> s;
cout << dfs(0, s.size() - 1) << endl;
return 0;
}