//DP求LCS LIS
#include<bits/stdc++.h>
int LCS()
{
memset(dp,0,sizeof(dp));
for(int i=0;i<=str1.length();i++)
for(int j=1;i<=str2.length();j++)
if(str1[i-1]==str2[j-1])
dp[i][j]=dp[i-1][j-1]+1;
else
dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
return dp[str1.length()][str2.length()];
}
int LIS()
{
int ans=1;
int dp[MAXN];
dp[1]=1;
for(int i=2;i<=n;i++){
int max=0;
for(int j=1;j<i;j++)
if(dp[j]>max&&high[j]<high[i])
max=dp[j];
dp[i]=max+1;
if(dp[i]>ans) ans=dp[i];
}
return ans;
}
DP与LIS LCS
最新推荐文章于 2022-07-21 21:00:12 发布