#include<stdio.h>
#include<string.h>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
#include<algorithm>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int N=1005;
int dp[N][N];
char str1[N],str2[N];
int main()
{
while(~scanf("%s %s",str1,str2))
{
int l1=strlen(str1);
int l2=strlen(str2);
memset(dp,0,sizeof(dp));
for(int i=1;i<=l1;i++)
{
for(int j=1;j<=l2;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]);
}
}
}
printf("%d\n",dp[l1][l2]);
}
return 0;
}
求最长公共子序列【lcs模板】
猜你喜欢
转载自blog.csdn.net/qq_41984014/article/details/84675528
今日推荐
周排行