P1435 [IOI2000] 回文字串 / [蓝桥杯 2016 省] 密码脱落https://www.luogu.com.cn/problem/P1435
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <set>
#include <cmath>
#include <map>
#include <cstdlib>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int MN = 65005;
const int MAXN = 2000010;
const int INF = 0x3f3f3f3f;
#define IOS ios::sync_with_stdio(false)
char s1[1005], s2[1005];
int dp[1005][1005];
int main() {
scanf("%s", s1 + 1);
int n = strlen(s1 + 1);
for (int i = 1; i <= n; i++) {
s2[i] = s1[ n - i + 1];
}
int maxx = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (s1[i] == s2[j]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
maxx = max(maxx, dp[i][j]);
}
}
printf("%d", n - maxx);
return 0;
}