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 最长公共子序列 题意 给你两个字符串,求出这两个字符串的最长公共子序列,这里的子序列不一定是连续的,只要满足前后关系就可以. 解题思路 这个当然 ...
随机推荐
- IAP (In-App Purchase)中文文档
内容转自:http://yarin.blog.51cto.com/1130898/549141 一.In App Purchase概览 Store Kit代表App和App Store之间进行通信.程 ...
- OAuth2.0授权和SSO授权
一. OAuth2.0授权和SSO授 1. OAuth2.0 --> 网页 --> 当前程序内授权 --> 输入账号密码 --> (自己需要获取到令牌, 自己处理逻辑) 授权成 ...
- HDU 1175 连连看(BFS)
连连看 Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- Ubuntu系统的安装
在上一篇博客中,我们已经建立了一个“空白”的虚拟Ubuntu镜像,在这篇博客中,我们将介绍如何安装并进入完整的Ubuntu系统. 写在前面:不同版本的系统在安装过程中,有些操作可能会不同,但是其核心步 ...
- 配置apache+trac环境
按照trac官网上的配置始终通不过.仔细看了,原来我们使用的apache版本是2.4的,在2.4中有些directive已经变了. 例如:原来的 Allow from all 现在变成了 Requir ...
- 诡异的XmlSerializer属性字段Specified
自动生成代码时,往往会为一个字段假设为 * , 生成另一个bool型字段: *Specified: 如: [Serializable] public class A { [XmlElement] pu ...
- 系统重装后phpnow修复
最近在捣鼓wordpress,主题写了一半然后就重装了win8,在新系统里面访问127.0.0.1的时候出现无法访问的情况.主题写了一半,又不想重装wordpress导数据库这些繁琐的过程,于是,尝试 ...
- c# winform textbox与combox让用户不能输入
textbox的ReadOnly属性设置为true combox的Enable属性设置为false 运行后效果如下 点击第一个和第二个,会把按钮text赋值给文本框和combox 并且用户不能输入
- simplexml 使用实例
搞了几天php处理xml文件,终于有点头绪,记录下来分享一下.simplexml 是php处理xml文件的一个方法,另一个是dom处理,这里只说simplexml.目前php处理xml用的比较多,比较 ...
- DSP:CCS V6 TMS320F2812 使用printf函数
使用Code Composer Studio Version: 6.1.1.00022,建立TMS320F2812工程. /* * main.c */ #include <stdio.h> ...