给定一个字符串s,你可以从中删除一些字符,使得剩下的串是一个回文串。如何删除才能使得回文串最长呢?
输出需要删除的字符个数。
经典编程题目啦~~
设原字符串s
原字符串反转的字符串t,回文串最长长度问题转为求LCS(s,t)的长度,画个二维数组就能明白原理,dp[i][j]表示 s 前 i 个字符与 t 前 j 个的公共最长子序列(LCS)长度
so easy~
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
const int maxn =