标签:
1 Ab3bd
2
1 #include<iostream> 2 #include<cstring> 3 using namespace std; 4 #define max(a,b) a > b ? a : b 5 const int maxn = 1001; 6 int dp[maxn][maxn]; 7 char s1[maxn],s2[maxn]; 8 int main(){ 9 int n; 10 cin >> n; 11 while(n--){ 12 int i,j; 13 cin >> s1; 14 int len = strlen(s1); 15 for(i = len - 1,j = 0;i >= 0;i--,j++) 16 s2[j] = s1[i]; 17 for(i = 1;i <= len;i++){ 18 for(j = 1;j <= len;j++){ 19 if(s1[i - 1] == s2[j - 1]){ 20 dp[i][j] = dp[i - 1][j - 1] + 1; 21 } 22 else 23 dp[i][j] = max(dp[i][j - 1],dp[i - 1][j]); 24 } 25 } 26 cout << len - dp[len][len] << endl; 27 } 28 return 0; 29 } 30
标签:
原文地址:http://www.cnblogs.com/zhengbin/p/4467697.html