您的位置:首页 > 产品设计 > UI/UE

hdu1159 Common Subsequence(LCS)

2015-11-03 22:01 471 查看
LCS的无敌大水题

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
#define maxn 500
int dp[maxn][maxn];
char str1[maxn],str2[maxn];

int main()
{
int i,j;
int m,n;
while(~scanf("%s%s",str1+1,str2+1))
{
memset(dp, 0, sizeof(dp));
m=strlen(str1+1);
n=strlen(str2+1);
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
if(str1[i]==str2[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[m]
);
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  dp