#include <stdio.h>
#include <string.h>
#define MAXN 1002
int dp[MAXN][MAXN];
int main()
{
char str1[MAXN],str2[MAXN];
int i,j,len1,len2;
while(scanf("%s %s",str1,str2)!=EOF)
{
memset(dp,0,sizeof(dp));
len1=strlen(str1);
len2=strlen(str2);
for (i=1;i<=len1;i++)
{
for (j=1;j<=len2;j++)
{
if(str1[i-1]==str2[j-1])
dp[i][j]=dp[i-1][j-1]+1;
else
dp[i][j]=(dp[i-1][j]>dp[i][j-1])?dp[i-1][j]:dp[i][j-1];
}
}
printf("%d\n",dp[len1][len2]);
}
return 0;
}
hdu1159 Common Subsequence
最新推荐文章于 2016-03-21 10:58:05 发布