HDOJ --- 1159 Common Subsequence
Common Subsequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 20815 Accepted Submission(s): 8954
The program input is from a text file. Each data set in the file contains two strings representing the given sequences. The sequences are separated by any number of white spaces. The input data are correct. For each set of data the program prints on the standard output the length of the maximum-length common subsequence from the beginning of a separate line.
programming contest
abcd mnp
思路:dp[i][j]表示str1的第i-1个字符和str2的第j-1个字符的最大的LCS,str[i-1] == str[j-1]时,dp[i][j] = dp[i-1][j-1] + 1 ; else : dp[i-1][j-1] = max(dp[i-1][j],dp[i][j-1]) .
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;
string str1, str2;
int dp[][];
int main(){
/* freopen("in.c", "r", stdin); */
while(cin >> str1 >> str2){
memset(dp, , sizeof(dp));
for(int i = ;i <= str1.size();i ++){
for(int j = ;j <= str2.size();j ++){
if(str1[i-] == str2[j-]) dp[i][j] = dp[i-][j-] + ;
else dp[i][j] = max(dp[i-][j], dp[i][j-]);
}
}
printf("%d\n", dp[str1.size()][str2.size()]);
str1.clear(), str2.clear();
}
return ;
}
HDOJ --- 1159 Common Subsequence的更多相关文章
- HDOJ 1159 Common Subsequence【DP】
HDOJ 1159 Common Subsequence[DP] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- Hdoj 1159.Common Subsequence 题解
Problem Description A subsequence of a given sequence is the given sequence with some elements (poss ...
- hdoj 1159 Common Subsequence【LCS】【DP】
Common Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HDU 1159 Common Subsequence
HDU 1159 题目大意:给定两个字符串,求他们的最长公共子序列的长度 解题思路:设字符串 a = "a0,a1,a2,a3...am-1"(长度为m), b = "b ...
- HDU 1159 Common Subsequence 公共子序列 DP 水题重温
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1159 Common Subsequence Time Limit: 2000/1000 MS (Jav ...
- hdu 1159 Common Subsequence(最长公共子序列)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1159 Common Subsequence Time Limit: 2000/1000 MS (Jav ...
- hdu 1159 Common Subsequence(最长公共子序列 DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1159 Common Subsequence Time Limit: 2000/1000 MS (Jav ...
- HDU 1159 Common Subsequence(裸LCS)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1159 Common Subsequence Time Limit: 2000/1000 MS (Jav ...
- HDU 1159 Common Subsequence 最长公共子序列
HDU 1159 Common Subsequence 最长公共子序列 题意 给你两个字符串,求出这两个字符串的最长公共子序列,这里的子序列不一定是连续的,只要满足前后关系就可以. 解题思路 这个当然 ...
随机推荐
- CSS 的选择符
CSS是什么? 如果说元素是标记代码的构建块料,那么CSS就是约束这些构建块料样式的规则. CSS规则的组成 CSS的规则由 选择符 和属性,值组成. Css选择符:选择符是规则中用于确定样式所涵盖的 ...
- ISO 学习笔记 2015-03-15
Objective--C 一 关键字 @property 定义变量函数 @synthesize 实现变量函数 二 函数 alloc 分配内存 init 初始化 new 替代上面两个函数 分配内存,并且 ...
- ubuntu tengine 安装
参考文章:http://wangyan.org/blog/install-openssl-from-source.html http://www1.site90.com/Linux/405.html ...
- 比较全面的gdb调试命令
from:http://blog.csdn.net/xiajun07061225/article/details/8960332 http://blog.csdn.net/cjfeii/article ...
- 深入了解absolute
1.absolute与float的相同的特性表现 a.包裹性 b.破坏性:父元素没有设置高或宽,父元素的高或宽取决于这个元素的内容 c.不能同时存在 2.absolute独立使用,不与relat ...
- @font-face
/** * jQuery.hhNewSilder 滚动图片插件 * User: huanhuan * QQ: 651471385 * Email: th.wanghuan@gmail.com ...
- JavaScript入门介绍(二)
JavaScript入门介绍 [函数] 函数function 是Javascript的基础模块单元,用于代码的复用.信息影藏和组合调用. function a(){} 函数对象Function Lit ...
- 表格table样式布局设置
<style> table{ border-collapse:collapse; margin:0 auto;} table tr td{ border:1px solid #000; l ...
- View和ViewGroup的区别 -- Touch事件处理
View.java源码: /frameworks/base/core/java/android/view/View.java View.java的 dispatchTouchEvent 方法: 经过一 ...
- python—cookielib模块对cookies的操作
最近用python写爬虫爬了点数据,确实是很好用的东西,今天对python如何操作cookie进行一下总结. python内置有cookielib模块操作cookie,配合urllib模块就可以了很轻 ...