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 ...
随机推荐
- MATLAB中.m文件生成.dll
1.配置编译环境 在命令行窗口输入: mbuild -setup 如果出现以下提示信息说明成功: 如果提示信息为: 错误使用mbuild(line 164) Unable to complete su ...
- HTML5游戏2D开发引擎
1.PixiJS(基于webGl和canvas) 官网:http://www.pixijs.com/ github(star:20672):https://github.com/pixijs/pixi ...
- 二分法:从一个只包含数字的list中查找某个数
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2017/4/10 19:03 # @Author : MnCu # @Site : # ...
- c语言1博客作业05
一.本周作业头 这个作业属于那个课程 C语言程序设计II 这个作业要求在哪里 https://edu.cnblogs.com/campus/zswxy/SE2019-3/homework/9831 我 ...
- Display Tag Lib Table进行分页
Display Tag Lib是一个标签库,用来处理jsp网页上的Table,功能非常强,可以对的Table进行分页.数据导出.分组.对列排序等等,反正我在做项目时需要的功能它都给我提供了,而且使用起 ...
- Idea中提交SVN或git时,忽略某些文件不提交
第一步:点击 setting 第二步:点击Editor下的File Types 第三步:编辑,在后面添加 *.iml;*.idea;*.gitignore;*.sh;*.classpath;*.pro ...
- hash 跟B+tree的区别
1.hash只支持in跟=,不支持范围查询,时间复杂度:O(1) 2.B+tree支持范围查询,时间复杂度:O(log n) 3. B+tree 的优点:1.磁盘读取代价更低 ...
- 002_FreeRTOS临界段代码
(一)临界段代码也叫做临界区,是指那些必须完整运行,不能被打断的代码段 (二)FreeRTOS 与 临 界 段 代 码 保 护 有 关 的 函 数 有 4 个,两个是任务级的临界段代码保护,两个是中断 ...
- VSCode 插件和快捷键(MAC)
1. 插件 1. JSON 格式优化--- JSON Tools 快捷键: 1). 格式化json字符串 Mac: Cmd+Option+M win: Ctrl+Alt+M 2).压缩json Ma ...
- Linux环境下levelDB源码编译与安装
1.下载源码并编译 git clone https://github.com/google/leveldb.git cd leveldb //编译源码的时候需要安装cmake,并且版本需要大于3.9, ...