找字符串里最长回文串的长度(不一定连续)
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
const int N = 1010;
int f[N][N];
int main(){
string s;
cin>>s;
string b(s);
reverse(b.begin(),b.end());
for(int i = 1;i<=s.size();i++){
for(int j = 1;j<=s.size();j++){
f[i][j] = max(f[i-1][j],f[i][j-1]);
if(s[i-1] == b[j-1]) f[i][j] = max(f[i][j],f[i-1][j-1]+1);
}
}
cout<<s.size()-f[s.size()][s.size()];
return 0;
}