首页 > 代码库 > hdu1159Common Subsequence(最长公共子序列)
hdu1159Common Subsequence(最长公共子序列)
题目链接: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(最长公共子序列)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。