首页 > 其他 > 详细

hdu1159Common Subsequence(最长公共子序列)

时间:2017-03-23 01:18:23      阅读:241      评论:0      收藏:0      [点我收藏+]

 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1159

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 const int maxn=1010;
 6 char s[maxn],t[maxn];
 7 int dp[maxn][maxn];
 8 
 9 int main()
10 {
11     while(scanf("%s",s+1)!=EOF)
12     {
13         memset(dp,0,sizeof(dp));
14         scanf("%s",t+1);
15         int sl=strlen(s+1);
16         int tl=strlen(t+1);
17         for(int i=1;i<=sl;i++)
18         {
19             for(int j=1;j<=tl;j++)
20             if(s[i]==t[j]) dp[i][j]=dp[i-1][j-1]+1;
21             else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
22         }
23         printf("%d\n",dp[sl][tl]);
24     }
25 }

 

hdu1159Common Subsequence(最长公共子序列)

原文:http://www.cnblogs.com/yijiull/p/6602515.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!