Common Subsequence

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 39661    Accepted Submission(s): 18228

Problem Description
A subsequence of a given sequence is the given sequence with some elements (possible none) left out. Given a sequence X = <x1, x2, ..., xm> another sequence Z = <z1, z2, ..., zk> is a subsequence of X if there exists a strictly increasing sequence <i1, i2, ..., ik> of indices of X such that for all j = 1,2,...,k, xij = zj. For example, Z = <a, b, f, c> is a subsequence of X = <a, b, c, f, b, c> with index sequence <1, 2, 4, 6>. Given two sequences X and Y the problem is to find the length of the maximum-length common subsequence of X and Y.
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
4
2
0
 

题意就是求两个字符串的最长公共子序列的长度。

LCS入门,传送门1:http://blog.csdn.net/liufeng_king/article/details/8500084

传送门2:http://blog.csdn.net/orbit/article/details/6717125

代码:

#include<bits/stdc++.h>
using namespace std;
const int N=1e3+;
char s1[N],s2[N];
int dp[N][N];
int len1,len2;
void fun(){
memset(dp,,sizeof(dp));
for(int i=;i<=len1;i++){
for(int j=;j<=len2;j++){
if(s1[i-]==s2[j-])
dp[i][j]=dp[i-][j-]+;
else
dp[i][j]=max(dp[i-][j],dp[i][j-]);
}
}
}
int main(){
while(~scanf("%s%s",&s1,&s2)){
len1=strlen(s1);
len2=strlen(s2);
fun();
printf("%d\n",dp[len1][len2]);
}
return ;
}

HDU1159-Common Subsequence-LCS的更多相关文章

  1. 动态规划求最长公共子序列(Longest Common Subsequence, LCS)

    1. 问题描述 子串应该比较好理解,至于什么是子序列,这里给出一个例子:有两个母串 cnblogs belong 比如序列bo, bg, lg在母串cnblogs与belong中都出现过并且出现顺序与 ...

  2. HDU1159 && POJ1458:Common Subsequence(LCS)

    Problem Description A subsequence of a given sequence is the given sequence with some elements (poss ...

  3. Common Subsequence LCS

    题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730#problem/F 题目: Description A subsequ ...

  4. 最长公共字串算法, 文本比较算法, longest common subsequence(LCS) algorithm

    ''' merge two configure files, basic file is aFile insert the added content of bFile compare to aFil ...

  5. Poj 1458 Common Subsequence(LCS)

    一.Description A subsequence of a given sequence is the given sequence with some elements (possible n ...

  6. HDU-1159 Common Subsequence 最长上升子序列

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...

  7. hdu 1159 Common Subsequence(LCS最长公共子序列)

    Common Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  8. 解题报告 HDU1159 Common Subsequence

    Common Subsequence Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u ...

  9. 解题报告:hdu1159 common consequence LCS裸题

    2017-09-02 17:07:42 writer:pprp 通过这个题温习了一下刚学的LCS 代码如下: /* @theme:hdu1159 @writer:pprp @begin:17:01 @ ...

  10. Longest Common Subsequence (LCS)

    最长公共子序列(LCS)是经典的DP问题,求序列a[1...n], b[1..m]的LCS. 状态是DP[i][j],表示a[1..i],b[1..j]的LCS. DP转移方程是 DP[i][j]= ...

随机推荐

  1. [array] leetcode - 39. Combination Sum - Medium

    leetcode - 39. Combination Sum - Medium descrition Given a set of candidate numbers (C) (without dup ...

  2. Smart line Panel和S7-200的MPI通信

    1.系统组成 2.一个简单任务 3.设置S7-200的通信参数 1)新建工程,设置CPU类型 2)设置端口1的通讯参数PLC地址为2,波特率187.5kbps 组态 3)保存完成配置 4.组态Smar ...

  3. bzoj 4446: [Scoi2015]小凸玩密室

    Description 小凸和小方相约玩密室逃脱,这个密室是一棵有n个节点的完全二叉树,每个节点有一个灯泡.点亮所有灯 泡即可逃出密室.每个灯泡有个权值Ai,每条边也有个权值bi.点亮第1个灯泡不需要 ...

  4. Activemq集群搭建

    集群搭建 一:静态网络集群 1.简介 ​ 当ActiveMQ面对大量消息存储和大量Client交互时,性能消耗将会达到单个broker极限,此时我们需要对ActiveMQ进行水平扩展.ActiveMQ ...

  5. MySql Schema 优化

    MySQL Schema 优化:   1.保证你的数据库的整洁性.   2.归档老数据 — 删除查询中检索或返回的多余的行   3.在数据上加上索引.   4.不要过度使用索引,评估你的查询.   5 ...

  6. vim 高级应用

    1 全文内容删除 方法1:    按ggdG方法2:       :%d

  7. 前端之 CSS🤖

    css (层叠样式表) : 对html标签的渲染和布局 查找 (选择器) 操作标签 (属性操作) 导入用 link 标签,后面的href就用你的文件路径就好 写css文件,要单独写到一个文件里面去 推 ...

  8. Python初体验

    今天开始所有的工作脚本全都从perl转变到python,开发速度明显降低了不少,相信以后随着熟练度提升会好起来.贴一下今天一个工作代码,由于之前去一家小公司测序时,序列长度竟然都没有达到要求,为了之后 ...

  9. HTML与HTML5复习标签汇总

    按字母顺序排列 New : HTML5 中的新标签. 标签 描述 <!--...--> 定义注释. <!DOCTYPE>  定义文档类型. <a> 定义锚. < ...

  10. vue2.0笔记《二》组件

    主要内容:如何注册组件.如何使用组件.父组件子组件之间值的传递 1.如何注册组件 第一步:通过import将子组件载入父组件的js中 // 第一步:通过import将子组件载入父组件的js中 impo ...