AcWing 1222. 密码脱落
原题链接
中等
作者:
最后五分钟
,
2024-03-29 15:29:38
,
所有人可见
,
阅读 5
#include<bits/stdc++.h>
#define LL long long
#define x first
#define y second
#define de(x) cout<<#x<<" = "<<x<<" "
#define deg(x) cout<<#x<<" = "<<x<<endl
using namespace std;
const int N=1010,M=10010;
typedef pair<int,int> PII;
int f[N][N];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string s;
cin>>s;
int n=s.size();
s=" "+s;
memset(f,0x3f,sizeof f);
for(int l=1;l<=n;l++)
for(int r=0;r<=l;r++)
f[l][r]=0;
for(int len=1;len<=n;len++)
for(int l=1;l+len-1<=n;l++)
{
int r=l+len-1;
if(s[l]!=s[r])f[l][r]=min(f[l][r-1]+1,f[l+1][r]+1);
else f[l][r]=f[l+1][r-1];
}
cout<<f[1][n]<<endl;
return 0;
}