hdu 1159 Common Subsequence(最长公共子序列 DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1159
Common Subsequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 25416 Accepted Submission(s):
11276
with some elements (possible none) left out. Given a sequence X = <x1, x2,
..., xm> another sequence Z = <z1, z2, ..., zk> is a subsequence of X
if there exists a strictly increasing sequence <i1, i2, ..., ik> of
indices of X such that for all j = 1,2,...,k, xij = zj. For example, Z = <a,
b, f, c> is a subsequence of X = <a, b, c, f, b, c> with index sequence
<1, 2, 4, 6>. Given two sequences X and Y the problem is to find the
length of the maximum-length common subsequence of X and Y.
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.
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; int dp[][]; int main()
{
char a[],b[];
while (~scanf("%s%s",a,b))
{
int len1=strlen(a);
int len2=strlen(b);
memset(dp,,sizeof(dp));
for (int i=len1-;i>=;i--)
{
for (int j=len2-;j>=;j--)
{
if (a[i]==b[j])
dp[i][j]=dp[i+][j+]+;
else
dp[i][j]=max(dp[i+][j],dp[i][j+]);
}
}
printf ("%d\n",dp[][]);
}
return ;
}
hdu 1159 Common Subsequence(最长公共子序列 DP)的更多相关文章
- HDU 1159 Common Subsequence 最长公共子序列
HDU 1159 Common Subsequence 最长公共子序列 题意 给你两个字符串,求出这两个字符串的最长公共子序列,这里的子序列不一定是连续的,只要满足前后关系就可以. 解题思路 这个当然 ...
- C++版 - Lintcode 77-Longest Common Subsequence最长公共子序列(LCS) - 题解
版权声明:本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C++版 - L ...
- POJ 1458 Common Subsequence(最长公共子序列LCS)
POJ1458 Common Subsequence(最长公共子序列LCS) http://poj.org/problem?id=1458 题意: 给你两个字符串, 要你求出两个字符串的最长公共子序列 ...
- lintcode 77.Longest Common Subsequence(最长公共子序列)、79. Longest Common Substring(最长公共子串)
Longest Common Subsequence最长公共子序列: 每个dp位置表示的是第i.j个字母的最长公共子序列 class Solution { public: int findLength ...
- LCS(Longest Common Subsequence 最长公共子序列)
最长公共子序列 英文缩写为LCS(Longest Common Subsequence).其定义是,一个序列 S ,如果分别是两个或多个已知序列的子序列,且是所有符合此条件序列中最长的,则 S 称为已 ...
- LCS修改版(Longest Common Subsequence 最长公共子序列)
题目描述 作为一名情报局特工,Nova君(2号)有着特殊的传达情报的技巧.为了避免被窃取情报,每次传达时,他都会发出两句旁人看来意义不明话,实际上暗号已经暗含其中.解密的方法很简单,分别从两句话里删掉 ...
- POJ 1458 Common Subsequence 最长公共子序列
题目大意:求两个字符串的最长公共子序列 题目思路:dp[i][j] 表示第一个字符串前i位 和 第二个字符串前j位的最长公共子序列 #include<stdio.h> #include&l ...
- LCS(Longest Common Subsequence)最长公共子序列
最长公共子序列(LCS)是一个在一个序列集合中(通常为两个序列)用来查找所有序列中最长子序列的问题.这与查找最长公共子串的问题不同的地方是:子序列不需要在原序列中占用连续的位置 .最长公共子序列问题是 ...
- PKU 1458 Common Subsequence(最长公共子序列,dp,简单)
题目 同:ZJU 1733,HDU 1159 #include <stdio.h> #include <string.h> #include <algorithm> ...
随机推荐
- SQL 中 Date 与Datetime的区别
Date是SQL Server 2008新引进的数据类型.它表示一个日子,不包含时间部分,可以表示的日期范围从公元元年1月1日到9999年12月31日.只需要3个字节的存储空间. DateTime 日 ...
- Mysql查询优化从入门到跑路(三)查询的基本操作
查询的基本操作 1.选择操作 对应的是限制条件,操作对象是二维表的行. 优化方式:选择操作下推 目的:尽量减少连接操作前的元租数,使得中间临时关系尽量少(元祖数少,连接得到的元组数就少 ...
- html5 拖拽练习题
html5新的拖拽 只支持Internet Explorer 9.Firefox.Opera 12.Chrome 以及 Safari 5 支持拖放. 来一个实例: <!DOCTYPE html& ...
- 【EF】解决EF批量操作,Z.EntityFramework.Extensions 过期方案
方案一: 使用EntityFramework.Extended优点: 启下载量是Z.EntityFramework.Extensions的10倍+ 不会过期缺点:不能批量Insert 方案二:解决批量 ...
- [转]matlab中squeeze函数的用法,numel的用法
squeeze的作用是移除单一维. 如果矩阵哪一个维数是1,B=squeeze(A)就将这个维数移除. 考虑2-by-1-by-3 数组Y = rand(2,1,3). 这个数组有单一维 —就是每页仅 ...
- BZOJ 1015 星球大战(并查集)
正着不好搞,考虑倒着搞.倒着搞就是一个并查集. # include <cstdio> # include <cstring> # include <cstdlib> ...
- (转)Ubuntu 12.04 LTS安装VMware Tools实现linux和window 互相复制:无法找到kernel header path的问题
Ubuntu 12.04 LTS安装VMware Tools无法找到kernel header path的问题 ubuntuvmware Ubuntu 12.04 安装 VMware Tools, ...
- 三个月死磕Python是种什么样的体验?
3个月的死磕Python后,参加「 楼+ Python实战 · 第4期 」的学员们感想如何?下面带来他们的真实评价. 作为实验楼的网红课程——「 楼+ Python实战 」已经走过了第四期,经过了三个 ...
- BZOJ4868:[SHOI2017]期末考试——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=4868 题目复制于洛谷:https://www.luogu.org/problemnew/show/P ...
- CF724E Goods transportation
最大流既视感 然后 TLEMLE既视感 然后 最大流=最小割 然后 dp[i][j]前i个点j个点在S集合,最小割 然后 dp[i][j]=min(dp[i-1][j]+p[i]+j*c,dp[i-1 ...