#include <iostream>
#include <string>
#include <vector>
using namespace std;
int palindrome2(string str){
int len = str.length();
vector<vector<bool>> dp(len,vector<bool>(len));
for(int i = len-1;i>=0;i--){
dp[i][i] = true;
for(int j = i+1;j<len;j++){
if(j - i < 2)
dp[i][j] = (str[i] == str[j]);
else
dp[i][j] = dp[i+1][j-1]&&(str[i] == str[j]);
}
}
vector<int> mincutDP(len+1);
mincutDP[0] = -1;
for(int i = 1;i<=len;i++){
mincutDP[i] = mincutDP[i-1]+1;
int curr = mincutDP[i];
for(int j = 1;j<=i;j++){
if(dp[j-1][i-1]){
curr = mincutDP[j-1]+1;
if(curr < mincutDP[i])
mincutDP[i] = curr;
}
}
}
return mincutDP[len];
}
int main()
{
string str = "abcdc";
cout<<palindrome2(str)<<endl;
getchar();
}