HDU 1159 Common Subsequence (动态规划、最长公共子序列)
Common Subsequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 55301 Accepted Submission(s): 25537
Problem Description
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.
Sample Input
abcfbc abfcab
programming contest
abcd mnp
Sample Output
题目大意与分析
就是求最长公共子序列,动态规划即可。
dp[i][j]代表A序列前i-1个元素与B序列前j-1个元素的最长公共子序列的个数,两层循环,相等就++,否则取当前最大的
代码
#include<bits/stdc++.h> using namespace std; string x,y;
int i,j,dp[][]; int main()
{
while(cin>>x>>y)
{
memset(dp,,sizeof(dp));
for(i=;i<x.size();i++)
{
for(j=;j<y.size();j++)
{
if(x[i]==y[j])
dp[i+][j+]=dp[i][j]+;
else
dp[i+][j+]=max(dp[i+][j],dp[i][j+]);
}
}
cout<<dp[x.size()][y.size()]<<endl;
}
}
HDU 1159 Common Subsequence (动态规划、最长公共子序列)的更多相关文章
- 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(LCS最长公共子序列)
Common Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- hdu 1159 Common Subsequence (最长公共子序列 +代码)
Problem Description A subsequence of a given sequence is the given sequence with some elements (poss ...
- 题解报告:hdu 1159 Common Subsequence(最长公共子序列LCS)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1159 Problem Description 给定序列的子序列是给定的序列,其中有一些元素(可能没有) ...
- HDU 1159 Common Subsequence 【最长公共子序列】模板题
题目链接:https://vjudge.net/contest/124428#problem/A 题目大意:给出两个字符串,求其最长公共子序列的长度. 最长公共子序列算法详解:https://blog ...
- hdu 1159 Common Subsequence(最长公共子序列,DP)
题意: 两个字符串,判断最长公共子序列的长度. 思路: 直接看代码,,注意边界处理 代码: char s1[505], s2[505]; int dp[505][505]; int main(){ w ...
- HDU - 1159 Common Subsequence (最长公共子序列)
A subsequence of a given sequence is the given sequence with some elements (possible none) left out. ...
- 杭电1159 Common Subsequence【最长公共子序列】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1159 解题思路:任意先给出两个字符串 abcfbc abfcab,用dp[i][j]来记录当前最长的子 ...
- HDU 1159 Common Subsequence 动态规划
2017-08-06 15:41:04 writer:pprp 刚开始学dp,集训的讲的很难,但是还是得自己看,从简单到难,慢慢来(如果哪里有错误欢迎各位大佬指正) 题意如下: 给两个字符串,找到其中 ...
- POJ 1458 Common Subsequence 【最长公共子序列】
解题思路:先注意到序列和串的区别,序列不需要连续,而串是需要连续的,先由样例abcfbc abfcab画一个表格分析,用dp[i][j]储存当比较到s1[i],s2[j]时最长公共子序 ...
随机推荐
- JavaScript 内置函数有什么?
javaScript内置函数 1.Date:日期函数 属性:constructor 所修立对象的函数参考prototype 能够为对象加进的属性和方法 方法:getDay() 返回一周中的第几天(0- ...
- javascript中的原型和原型链(一)
原型和原型链是 JS 中不可避免需要碰到的知识点,本文使用图片思维导图的形式缕一缕原型.原型链.实例.构造函数等等概念之间的关系. Constructor 构造函数 首先我们先写一个构造函数 Pers ...
- Akka 介绍
欢迎使用 Akka,Akka 是一套被用来在在多处理器核心和网络之间被设计可扩展和具有相关弹性的开源工具集.Akka 允许你更加关注商业需求而不是书写低级别的代码来提供可靠性,容错率和高性能. 很多常 ...
- ABI与ARM,X86的概念
Android系统目前支持以下七种不同的CPU架构:ARMv5,ARMv7 (从2010年起),x86 (从2011年起),MIPS (从2012年起),ARMv8,MIPS64和x86_64 (从2 ...
- PTA 道长你想怎么死
道长你想怎么死 (25 分) 故事:[ 他身着白衣,撑着伞朝我走来.说要送我回家.而我早已陷入他那对深邃的眼眸中,心内一阵悸动.他一把拉我入伞下.我得知他是山上的道士,也刚好下山采药.他把伞赠予我,一 ...
- What’s up with the Graph Laplacian
What's up with the Graph Laplacian? 来源 作者:Jeremy Kun blog: Math ∩ Programming 在数学上图和与图关联的某些矩阵的代数性质有很 ...
- CoreData编辑器
如何你开发iOS使用的是CoreData数据库的话,肯定想要一个可以查看和编辑CoreData数据库的工具,今天给大家推荐一个工具Core-Data-Editor 下载地址:https://githu ...
- 添加一个静态JAVA库
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) # Build all java files in the java subdirectory L ...
- DAY 3模拟赛
DAY3 钟皓曦来了! T1 网址压缩 [问题描述] 你是能看到第一题的 friends 呢. ——hja 众所周知,小葱同学擅长计算,尤其擅长计算组合数,但这个题和组合数没什么关 ...
- Eureka入门一(了解概念)
Eureka注册中心(8761端口) IDEA(开发工具) 1,创建项目勾选Eureka Server 2, 创建yml文件,拷贝配置,下面配置必须为false,意为,该项目不要作为客户端注册,因为本 ...