|
沙发
楼主 |
发表于 2018-7-15 09:00:58
|
只看该作者
- #include<iostream>
- #include<cstdio>
- using namespace std;
- int i,j,n,f[2000][2000],ans;
- char c1[2000],c2[2000];
- int main()
- {
- while(scanf("%s",c1)!=EOF)continue;
- while(c1[n++]!=0)continue;
- n--;
- for(i=0;i<n;i++)
- c2[i]=c1[n-i-1];
- for(i=1;i<=n;i++)
- {
- for(j=1;j<=n;j++)
- {
- if(c1[i-1]==c2[j-1])f[i][j]=f[i-1][j-1]+1;
- else f[i][j]=max(f[i-1][j],f[i][j-1]);
- /// cout<<i<<" "<<j<<" "<<f[i][j]<<endl;
- }
- }
- /*for(i=0;i<n;i++)cout<<c2[i];
- cout<<endl<<n<<endl;
- cout<<f[n][n];*/
- ans=n-f[n][n];
- cout<<ans;
- return 0;
- }
复制代码 |
|