poj 1458 Common Subsequence
来源:互联网 发布:淘宝宝贝描述软件 编辑:程序博客网 时间:2024/06/11 23:41
分类:dp 难度:1
题意:求两字符串的最长公共字串。
a[i]==b[j],dp[i][j] = dp[i-1][j-1]+1,,否则 dp[i][j] = MAX(dp[i-1][j],dp[i][j-1])
#include<cstdio>#include<cstring>#include<iostream>#include<string>#define MAX(x,y) (x)>(y)?(x):(y)using namespace std;const int N=510;int dp[N][N];string a,b;int cal(int i,int j){if(i<0 || j<0) return 0;if(dp[i][j]>=0) return dp[i][j];if(a[i]==b[j]) dp[i][j] = cal(i-1,j-1)+1;else dp[i][j] = MAX(cal(i-1,j),cal(i,j-1));return dp[i][j];}int main(){while(cin>>a>>b){memset(dp,-1,sizeof(dp));int la=a.length(),lb=b.length();int i,j;int ans=0;ans = cal(la-1,lb-1);printf("%d\n",ans);}}
- Common Subsequence--poj--1458
- poj 1458 Common Subsequence
- poj 1458 Common Subsequence
- Poj 1458 Common Subsequence
- POJ 1458 Common Subsequence
- poj 1458 Common Subsequence
- poj 1458 Common Subsequence
- POJ 1458 Common Subsequence
- poj 1458 Common Subsequence
- POJ-1458-Common Subsequence
- POJ 1458 Common Subsequence
- poj 1458 Common Subsequence
- POJ 1458 Common Subsequence
- poj 1458 Common Subsequence
- POJ 1458 Common Subsequence
- POJ 1458 Common Subsequence
- POJ 1458 Common Subsequence
- poj 1458 Common Subsequence
- linux网络协议栈分析笔记7-VLAN的处理
- codeforces round#177 E
- 计算机是如何启动的
- OpenGL ES实例1:上下跳动的正方形
- C++ pair用法
- poj 1458 Common Subsequence
- 外部排序
- 番茄工作法--方法篇
- 课程大纲:测试用例设计与测试管理实践课程
- 番茄工作法--问题篇
- 开源 免费 java CMS - FreeCMS1.2-标签 commentPage
- Oracle CASE WHEN 用法介绍
- HelloWorld
- Thread.sleep() 和Thread.currentThread().sleep()的区别