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 ...
随机推荐
- WCF Endpoint分类
WCF中可以为一个Service配置多个Endpoint 这些Endpoint的分类方法有下面3中 1.全局就一个endpoint,一个接口公开所有的方法,这适合简单的业务场景 2.将endpoint ...
- JQuery 遍历 操作数组 map、grep、filter 的区别
filter() 方法将匹配元素集合缩减为匹配指定选择器的元素.例如:改变所有 div 的颜色,然后向类名为 "middle" 的类添加边框:$("div"). ...
- Node.js Websocket 区分不同的用户
实现ws://serverIP:port/:param1/:param2 .通过param1,param2来管理不同的ws回话,以便实现群发和指定用户的消息推送 npm install ws --sa ...
- LOJ2265. 「CTSC2017」最长上升子序列
题意:中文题意很清楚 LOJ2263 分析: 根据Dilworth定理,最小链覆盖=最长反链. 问题转化为求 $k$ 个最小不上升序列能覆盖的最大数的个数. 参考链接: 1. https://blog ...
- django获取数据
获取单个值 request.POST.get('user') # user对应前端name属性对应的值 获取多个值(如checkbox,multiple) request.POST.getlist(' ...
- 【题解】狼和羊-C++
Description 米基家的后院养着一群羊,米基由于疲劳睡着了,这时一群饿狼钻进了后院开始攻击羊群,后院是由许多个方格构成的长方形区域,每个方格中用字符'?'表示空地,'#'表示栅栏,'o'表示羊 ...
- IDEA更改Maven项目的webapp的版本号
使用Maven新建的web项目后默认的web.xml为2.3的,以前每次都是从其他文件中拷贝过来的2.5或者3.1的进行替换,怎样指定默认创建web项目的版本? 1.使用IDEA的Help文档具体的过 ...
- Security Study
1.WebGoat http://www.owasp.org.cn/ 学习Web应用漏洞最好的教程----WebGoat http://blog.csdn.net/bill_lee_sh_cn/art ...
- 百度ueditor中复制word图文时图片转存任然保持灰色不可用
官网地址http://ueditor.baidu.com Git 地址 https://github.com/fex-team/ueditor 参考博客地址 http://blog.ncmem.com ...
- Domain Socket本地进程间通信
socket API原本是为网络通讯设计的,但后来在socket的框架上发展出一种IPC机制,就是UNIX Domain Socket.虽然网络socket也可用于同一台主机的进程间通讯(通过loop ...