HDU 1159 最长公共子序列
Common Subsequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 53443 Accepted Submission(s): 24607
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.
abcfbc abfcabprogramming contestabcd mnp
420
【题意】
一个给定序列的子序列是一个给定序列,其中有些元素(可能没有)被省略。给定一个序列 X = <x1, x2, ..., xm> 另一个序列 Z = <z1, z2, ..., zk> 是X的子序列,如果存在严格递增序列, <i1, i2, ..., ik> 对所有 j = 1,2,…,k, xij = zj。例如,Z = <a, b, f, c> 是 X = <a, b, c, f, b, c> 的子序列,索引序列< 1,2,4,6 >。给定两个序列X和Y,问题是求X和Y的最大长度公共子序列的长度。
序列由任意数量的空格分隔。输入数据是正确的。对于每组数据,程序在标准输出上打印从单独行开始的最大长度公共子序列的长度。
注意:最长公共子序列 ,可以不连续。
【代码】
#include<bits/stdc++.h>
#define MAX 5005
using namespace std;
int f[MAX][MAX];
string s,t;
int main(){
while(cin>>s>>t){
for(int i=;i<=s.length();i++)
for(int j=;j<=t.length();j++){
f[i][j]=max(f[i-][j],f[i][j-]);
if(s[i-]==t[j-])
f[i][j]=max(f[i][j],f[i-][j-]+);
}
cout<<f[s.length()][t.length()]<<endl;
}
return ;
}
HDU 1159 最长公共子序列的更多相关文章
- HDU 1159 最长公共子序列(n*m)
Common Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- POJ 1159 Palindrome-最长公共子序列问题+滚动数组(dp数组的重复利用)(结合奇偶性)
Description A palindrome is a symmetrical string, that is, a string read identically from left to ri ...
- HDU - 1503 最长公共子序列记录路径
题意:先给两个水果的名字然后得出一个最短的序列包含这两个词. 思路:我一开始的思路是先求出最长公共子序列,然后做一些处理将其他的部分输出来:两种水果的字符串和最长公共子序列的字符串这三个字符串做对比, ...
- HDU 1159 Common Subsequence 公共子序列 DP 水题重温
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1159 Common Subsequence Time Limit: 2000/1000 MS (Jav ...
- hdu 4681 最长公共子序列+枚举
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4681 #include<cstdio> #include<cstring> # ...
- hdu 1503 最长公共子序列
/* 给两个串a,b.输出一个最短的串(含等于a的子序列且含等于b的子序列) */ #include <iostream> #include <cstdio> #include ...
- hdoj 1159最长公共子序列
/*Common Subsequence A subsequence of a given sequence is the given sequence with some elements ( ...
- HDU 1159 Common Subsequence:LCS(最长公共子序列)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1159 题意: 求最长公共子序列. 题解: (LCS模板题) 表示状态: dp[i][j] = max ...
- hdu 1159 Common Subsequence(最长公共子序列)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1159 Common Subsequence Time Limit: 2000/1000 MS (Jav ...
随机推荐
- [ 转载 ]hashCode方法的相关用法
想要明白hashCode的作用,你必须要先知道Java中的集合. 总的来说,Java中的集合(Collection)有两类,一类是List,再有一类是Set. 你知道它们的区别吗?前者集合内的元素是有 ...
- SQL SERVER 查询第20行到30之间的数据
1.先查询前20行的ID,后查询除去20条记录的前10条记录 SELECT TOP * FROM tbBank WHERE BankID NOT IN(SELECT TOP BankID FROM t ...
- es批量导入进一对多的数据
es批量导入进一对多的数据 我有一个产品表 一个产品对应多个属性名 一个属性名对应多个属性值 一个产品还对应一个分类名称 控制层 @ApiOperation(value = "导入所有 ...
- 11 - Vue模板语法
Vue.js 使用了基于 HTML 的模板语法,允许开发者声明式地将 DOM 绑定至底层 Vue 实例的数据. 所有 Vue.js 的模板都是合法的 HTML ,所以能被遵循规范的浏览器和 HTML ...
- pymysql基本使用
导入模块 import pymysql 连接(看一下password有没有,没有的话会怎么样,有很多参数,有些参数也是可以不传的) conn = pymysql.connect(user = &quo ...
- css定位中的百分比
----转载自自己在牛人部落中的相关文章--- 在前端css定位中经常面对的一个问题是,百分比定位究竟是针对于谁定位? 一.margin,padding的百分比 首先从css的设计意图说起,在浏览器默 ...
- Flutter安装
下载右边的安装包以获取最新版本 stable 的 Flutter SDK 将压缩包解压,然后把其中的 flutter 目录整个放在你预想的 Flutter SDK 安装目录中(比如 C:\src\fl ...
- CISCO实验记录十:switch基本配置
1.交换机IP配置 2.配置telnet 1.交换机IP配置 #interface vlan 1 #ip address 192.168.0.3 255.255.255.0 #no shutdown ...
- OpenResty之ngx.ssl
翻译自: ngx.ssl - Lua API for controlling NGINX downstream SSL handshakes 1. 概要 # 注意:如果你使用的是 OpenResty ...
- 第11组 Beta冲刺(2/5)
第11组 Beta冲刺(2/5) 队名 不知道叫什么团队 组长博客 https://www.cnblogs.com/xxylac/p/11997386.html 作业博客 https://edu. ...