标签:blog http io ar os sp for div on
1 Ab3bd
2
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<string> #include<cmath> #include<algorithm> using namespace std; int n,f[1001][1001]; char s1[1001],s2[1001]; int main() { scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%s",s1); memset(f,0,sizeof(f)); int len=strlen(s1); for(int i=len-1;i>=0;i--) s2[len-i-1]=s1[i]; for(int i=1;i<=len;i++) for(int j=1;j<=len;j++) if(s1[i-1]==s2[j-1]) f[i][j]=f[i-1][j-1]+1; else f[i][j]=max(f[i-1][j],f[i][j-1]); printf("%d\n",len-f[len][len]); } return 0; }
标签:blog http io ar os sp for div on
原文地址:http://www.cnblogs.com/a972290869/p/4099969.html