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]时最长公共子序 ...
随机推荐
- 记Springcloud Config Service整合gitlab一坑
spring.cloud.config.server.git.uri=http://ip/***/configserver.git必须加上.git
- Python网络爬虫_爬取Ajax动态加载和翻页时url不变的网页
1 . 什么是 AJAX ? AJAX = 异步 JavaScript 和 XML. AJAX 是一种用于创建快速动态网页的技术. 通过在后台与服务器进行少量数据交换,AJAX 可以使网页实现异步更新 ...
- npoi 导入
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CusImport.aspx ...
- JavaScript生成随机数的方法
一,函数 Math.ceil(); //向上取整. Math.floor(); //向下取整. Math.round(); //四舍五入. Math.random(); //0.0 ~ 1.0 ...
- [pwnable.kr]Dragon
0x00: dragon 是一个UAF漏洞的利用. UseAfterFree 是堆的漏洞利用的一种 简单介绍 https://www.owasp.org/index.php/Using_freed_m ...
- Protocol Buffers 开发者指南
欢迎来到 protocol buffers 的开发者指南.protocol buffers 是一个语言中立,平台中立针对通讯协议,数据存储和其他领域中对结构化数据进行序列化的扩展方法. 本文档主要针对 ...
- python动态的添加方法
1.动态的创建实例方法 1 class Person(object): 2 def __init__(self,name,age): 3 self.name = name 4 self.age =ag ...
- Make文件(一)
基本规则: 目标:依赖 (tab)规则 目标:需要生成的目标文件 依赖:生成该目标所需的一些文件 规则:由依赖文件生成目标文件的手段 tab:每条规则前必须以tab开头,使用空格不行. 例如: /** ...
- AcWing 107. 超快速排序(归并排序 + 逆序对 or 树状数组)
在这个问题中,您必须分析特定的排序算法----超快速排序. 该算法通过交换两个相邻的序列元素来处理n个不同整数的序列,直到序列按升序排序. 对于输入序列9 1 0 5 4,超快速排序生成输出0 1 4 ...
- C++入门经典-例2.14-使用移位运算
1:代码如下: // 2.14.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> usin ...