题目:http://poj.org/problem?id=1159
1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 using namespace std; 5 6 int mmin(int a,int b) 7 { 8 return a>b?b:a; 9 } 10 short int d[5010][5010]; 11 int main() 12 { 13 int n,i,j; 14 char s[5010]; 15 memset(d,0,sizeof(d)); 16 cin>>n; 17 for(i=1; i<=n; i++) 18 cin>>s[i]; 19 for(i=n; i>=1; i--) 20 for(j=i+1; j<=n; j++) 21 if(s[i]==s[j]) 22 d[i][j]=d[i+1][j-1]; 23 else 24 d[i][j]=mmin(d[i+1][j],d[i][j-1])+1; 25 26 cout<<d[1][n]<<endl; 27 return 0; 28 }