#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <set>
#include <math.h>
#define eps 1e-14
#define pi acos(-1)
#define ll long long
#define RD T*(rand()*2-RAND_MAX)
#define Drand (long double)rand()/RAND_MAX
#define LINF 0x7f7f7f7f7f7f7f7f
#define INF 0x3f3f3f3f
using namespace std;
const int maxn=1005;
const long long mod=1e18;
ll MOD(ll a,ll m){return a>m?a%m+m:a;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dp[maxn][maxn];
char a[maxn],b[maxn];
int main()
{
// freopen("in.txt","r",stdin);
while(~scanf("%s%s",a+1,b+1)){
memset(dp,0,sizeof dp);
a[0]=1;
b[0]=1;
int lena=strlen(a);
int lenb=strlen(b);
for(int i=1;i<lena;i++){
for(int j=1;j<lenb;j++){
if(a[i]==b[j])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[lena-1][lenb-1]);
}
return 0;
}
POJ 1458 最长公共子序列dp
最新推荐文章于 2020-12-09 08:50:01 发布