最好别把初始化和状态转移混在一起
#include<iostream>
#include<cstring>
using namespace std;
const int N = 1010;
int f[N][N];
char arr[N];
int main(){
cin>>(arr+1);
int sz = strlen(arr+1);
for(int len = 1;len<=sz;len++){
for(int i = 1;i<=sz-len+1;i++){
int j = i+len-1;
if(i == j) f[i][j] = 1;
else{
if(arr[i] == arr[j]) f[i][j] = max(f[i][j],f[i+1][j-1]+2);
f[i][j] = max(f[i][j],f[i+1][j]);
f[i][j] = max(f[i][j],f[i][j-1]);
f[i][j] = max(f[i][j],f[i+1][j-1]);
}
}
}
cout<<sz-f[1][sz];
return 0;
}