#include "string"
#include "iostream"
#include "cstdio"
#include "cmath"
#include "set"
#include "queue"
#include "vector"
#include "cctype"
#include "sstream"
#include "cstdlib"
#include "cstring"
#include "stack"
#include "ctime"
#include "algorithm"
#define pa pair<int,int>
#define Pi M_PI
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef long long LL;
const int M=1500;
#define N 1000
int dp[M][M];
int main()
{
int i,j;
string s1,s2;
int l1,l2;
while(cin>>s1>>s2)
{
l1=s1.length();
l2=s2.length();
memset(dp,0,sizeof(dp));
for(i=1;i<=l1;++i)
for(j=1;j<=l2;++j)
{
if(s1[i-1]==s2[j-1])
dp[i][j]=dp[i-1][j-1]+1;
else
dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
}
cout<<dp[l1][l2]<<endl;
}
return 0;
}
HDU 1159 Common Subsequence(最长公共子序列)
最新推荐文章于 2020-03-18 19:33:38 发布