POJ 1458-Common Subsequence(dp之最长公共子序列)
2015-08-18 19:40
501 查看
题目地址:POJ 1458
题意:给出两个序列X 和Y,你的任务是找到X 和Y 的最大公共子序列,也就是说要找到一个最长的序列Z,使得Z 既是X 的子序列也是Y 的子序列。
思路:最长公共子序列的裸题,关于最长公共子序列问题,请看最长公共子序列
题意:给出两个序列X 和Y,你的任务是找到X 和Y 的最大公共子序列,也就是说要找到一个最长的序列Z,使得Z 既是X 的子序列也是Y 的子序列。
思路:最长公共子序列的裸题,关于最长公共子序列问题,请看最长公共子序列
#include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include <iostream> #include <sstream> #include <algorithm> #include <set> #include <queue> #include <stack> #include <map> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; typedef long long LL; const int inf=0x3f3f3f3f; const double pi= acos(-1.0); const double esp=1e-7; const int Maxn=1010; int dp[Maxn][Maxn]; char str1[Maxn],str2[Maxn]; int main() { while(~scanf("%s %s",str1+1,str2+1)){ int len1=strlen(str1+1); int len2=strlen(str2+1); for(int i=0;i<=len1;i++) dp[i][0]=0; for(int i=0;i<=len2;i++) dp[0][i]=0; for(int i=1;i<=len1;i++){ for(int j=1;j<=len2;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[len1][len2]); } return 0; }
相关文章推荐
- Arithmetic Sequence
- UESTC 360 Another LCIS (线段树 维护LCIS)
- cat /proc/cpuinfo 引发的思考--CPU 物理封装-物理核心-逻辑核心-超线程之间关系
- Children’s Queue 1297 (大数)
- Chapter5 : View controller & KVC - The Big Nerd Ranch Guide 读书笔记
- HDU-5400 Arithmetic Sequence(数学 || DP)
- java 中break、continue、return之间的区别与联系
- hdu5400Arithmetic Sequence
- PowerBuilder中使用JDBC连接MYSQL 无法使用COUNT(*) MAX() 函数的处理
- 合成UIImageView,改变尺寸
- 使用YUI Compressor压缩JS和Css,批处理,右键,注册表,打包
- iOS UIImage剪切圆形
- UIView的“截屏”
- Mybatis select返回值为map时,选取表字段的两列作为key,value
- STL 整理(map、set、vector、list、stack、queue、deque、priority_queue)
- easyui datebox 扩展 只显示年月
- /proc/cpuinfo
- Null value was assigned to a property of primitive type setter of
- easyui数据窗口datagrid的数据加载问题
- HDU5400 Arithmetic Sequence 数学题