HDU1159 && POJ1458:Common Subsequence(LCS)
来源:互联网 发布:数据库开发需要学什么 编辑:程序博客网 时间:2024/04/28 06:19
必须得啃DP了,就从最简单的DP入门题开始了。
#include <iostream>#include <cstdio>#include <string>#include <cstring>using namespace std;string str1,str2;int pos[1005][1005];int main(){while(cin>>str1>>str2){int length1=str1.size();int length2=str2.size();memset(pos,0,sizeof(pos));for(int i=1;i<=length1;i++){for(int j=1;j<=length2;j++){if(str1[i-1]==str2[j-1]){pos[i][j]=pos[i-1][j-1]+1;}else{pos[i][j]=max(pos[i-1][j],pos[i][j-1]);}}}cout<<pos[length1][length2]<<endl;}return 0;}滚动数组优化
#include <iostream>#include <cstdio>#include <string>#include <cstring>using namespace std;string str1,str2;int pos[2][1005];int main(){while(cin>>str1>>str2){int length1=str1.size();int length2=str2.size();memset(pos,0,sizeof(pos));for(int i=1;i<=length1;i++){for(int j=1;j<=length2;j++){if(str1[i-1]==str2[j-1]){pos[i%2][j]=pos[(i-1)%2][j-1]+1;}else{pos[i%2][j]=max(pos[(i-1)%2][j],pos[i%2][j-1]);}}}cout<<max(pos[0][length2],pos[1][length2])<<endl;}return 0;}
0 0
- HDU1159 && POJ1458:Common Subsequence(LCS)
- HDU1159 && POJ1458:Common Subsequence(LCS)
- HDU1159 && POJ1458 Common Subsequence (LCS)
- HDU1159 && POJ1458 Common Subsequence (LCS模版题)
- HDU1159 Common Subsequence (LCS)
- HDU1159:Common Subsequence(LCS)
- hdu1159 Common Subsequence(LCS)
- Hdu1159-Common Subsequence-【LCS】
- poj1458 Common Subsequence【LCS】
- hdu1159 Common Subsequence(LCS)
- 【HDU1159】Common Subsequence(LCS/DP)
- HDU1159 Common Subsequence (LCS)
- HDU1159 : Common Subsequence(LCS)
- POJ1458 && HDOJ1159 Common Subsequence【LCS】
- [dp]poj1458 -Common Subsequence(LCS)
- poj1458-LCS&回溯-Common Subsequence
- hdu1159/poj1458 Common Subsequence 动态规划
- Common Subsequence(hdu1159(LCS))
- uva 11462 更快的基数排序
- OC中类的函数参数问题,以及方法与函数的区别。
- 好像很有道理的样子
- 亚信大数据平台产品经理 杨晋:大数据是怎么应用于技术方面的
- 机器学习的9个基础概念和10种基本算法总结
- HDU1159 && POJ1458:Common Subsequence(LCS)
- mysqldump 备份MYSQL带存储过程和注释
- TreeMap的使用实例:统计字符出现次数
- PostgreSQL安装详细步骤(windows)
- 黑马程序员:JDBC的总结
- 使用man时条目后面的数字的含义
- [POJ3254] Corn Fields
- 复数加减
- 黑马程序员03