1.LCS
https://www.luogu.com.cn/problem/AT4527
2.LIS
3.CSD
#include<bits/stdc++.h>
using namespace std;
#define maxn 2005
int dp[maxn][maxn];
int main()
{
string a,b;
cin>>a>>b;
int alen=a.length();
int blen=b.length();
for(int i=1;i<maxn;i++)
dp[0][i]=i,dp[i][0]=i;
for(int i=1;i<=alen;i++)
for(int j=1;j<=blen;j++)
{
if(a[i-1]==b[j-1])
{
dp[i][j]=min(dp[i-1][j]+1,min(dp[i][j-1]+1,dp[i-1][j-1]));
}
else
{
dp[i][j]=min(dp[i-1][j]+1,min(dp[i][j-1]+1,dp[i-1][j-1]+1));
}
}
cout<<dp[alen][blen]<<endl;
}
4.最长回文子序列(LPS)
https://blog.csdn.net/lxt_Lucia/article/details/80085527
求最长回文子序列长度
求最长回文子序列个数
设字符串为str,长度为n,p[i][j]表示第i到第j个字符间的回文子序列个数(i<=j),则:
状态初始条件:dp[i][i]=1 (i=0:n-1)
状态转移方程:dp[i][j]=dp[i+1][j] + dp[i][j-1] - dp[i+1][j-1] if(str[i]!=str[j])(首尾去掉那段加重了)
dp[i][j]=dp[i+1][j] + dp[i][j-1] - dp[i+1][j-1]+dp[i+1][j-1]+1=dp[i+1][j] + dp[i][j-1]+1 if (str[i]==str[j])(首尾去掉那段加两边,相当于首尾去掉那段+首尾同时出现在首尾去掉那段里)
5.最长回文子串
https://blog.csdn.net/lxt_Lucia/article/details/80085527
马拉车O(N)其他都是O(N^2)