标签:
zzzzzfzzzzz abcdefedcba abababababab cdcdcdcdcdcd
6 7
1 #include <bits/stdc++.h> 2 using namespace std; 3 const int maxn = 120; 4 int dp[maxn][maxn],ans[maxn]; 5 char a[maxn],b[maxn]; 6 int main() { 7 while(~scanf("%s%s",a,b)) { 8 int n = strlen(a); 9 memset(dp,0,sizeof dp); 10 for(int i = n-1; i >= 0; --i) 11 for(int j = i; j < n; ++j) { 12 dp[i][j] = dp[i+1][j] + 1; 13 for(int k = i+1; k <= j; ++k) { 14 if(b[i] == b[k]) 15 dp[i][j] = min(dp[i][j],dp[i+1][k]+dp[k+1][j]); 16 } 17 } 18 memset(ans,0x3f,sizeof ans); 19 for(int i = 0; i < n; ++i) { 20 if(a[i] == b[i]) ans[i] = i?ans[i-1]:0; 21 else ans[i] = dp[0][i]; 22 for(int j = i-1; j >= 0; --j) 23 ans[i] = min(ans[i],ans[j]+dp[j+1][i]); 24 } 25 printf("%d\n",ans[n-1]); 26 } 27 return 0; 28 }
标签:
原文地址:http://www.cnblogs.com/crackpotisback/p/4668340.html