传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1260
这么水的dp都想错我真是太弱了……
Code:
#include<bits/stdc++.h>
using namespace std;
char s[55];
int f[55][55];
int main(){
scanf("%s",s+1);s[0]='#';
int n=strlen(s+1);
memset(f,0x3f,sizeof f);
for(int i=1;i<=n;i++)f[i][1]=1;
for(int j=2;j<=n;j++)
for(int i=1;i+j-1<=n;i++){
if(s[i]==s[i+j-1])f[i][j]=min(f[i+1][j],f[i][j-1]);
for(int k=1;k<j;k++)f[i][j]=min(f[i][j],f[i][k]+f[i+k][j-k]);
}cout<<f[1][n]<<endl;
return 0;
}