Common Subsequence
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 46387   Accepted: 19045

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.

Input

The program input is from the std input. Each data set in the input contains two strings representing the given sequences. The sequences are separated by any number of white spaces. The input data are correct.

Output

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

Source

 
就是求最长公共子序列
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
#define N 1010
char x[N],y[N];
short int f[N][N];
int main(){
while(scanf("%s%s",x+,y+)==){
int lx=strlen(x+),ly=strlen(y+);
for(int i=;i<=lx;i++)
for(int j=;j<=ly;j++)
if(x[i]==y[j])
f[i][j]=f[i-][j-]+;
else
f[i][j]=max(f[i-][j],f[i][j-]);
printf("%d\n",f[lx][ly]);
for(int i=;i<=lx;i++)for(int j=;j<=ly;j++)f[i][j]=;
}
return ;
}

poj 1458 Common Subsequence的更多相关文章

  1. LCS POJ 1458 Common Subsequence

    题目传送门 题意:输出两字符串的最长公共子序列长度 分析:LCS(Longest Common Subsequence)裸题.状态转移方程:dp[i+1][j+1] = dp[i][j] + 1; ( ...

  2. POJ 1458 Common Subsequence(LCS最长公共子序列)

    POJ 1458 Common Subsequence(LCS最长公共子序列)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?c ...

  3. OpenJudge/Poj 1458 Common Subsequence

    1.链接地址: http://poj.org/problem?id=1458 http://bailian.openjudge.cn/practice/1458/ 2.题目: Common Subse ...

  4. POJ 1458 Common Subsequence(最长公共子序列LCS)

    POJ1458 Common Subsequence(最长公共子序列LCS) http://poj.org/problem?id=1458 题意: 给你两个字符串, 要你求出两个字符串的最长公共子序列 ...

  5. POJ 1458 Common Subsequence (动态规划)

    题目传送门 POJ 1458 Description A subsequence of a given sequence is the given sequence with some element ...

  6. Poj 1458 Common Subsequence(LCS)

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

  7. poj 1458 Common Subsequence【LCS】

    Common Subsequence Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 43132   Accepted: 17 ...

  8. (线性dp,LCS) POJ 1458 Common Subsequence

    Common Subsequence Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 65333   Accepted: 27 ...

  9. POJ - 1458 Common Subsequence DP最长公共子序列(LCS)

    Common Subsequence A subsequence of a given sequence is the given sequence with some elements (possi ...

随机推荐

  1. absolute绝对定位可以实现相对定位

    没有设置定位值的absolute元素是个普通又不普通的元素,普通之处在于其依旧在DOM tree中,对margin等属性敏感: 不普通在于其实际的高宽都丢失了.这非常类似于浮动(float),浮动的本 ...

  2. 代码导出Reporting Services报表文件

    背景部分 使用Reporting Services很容易制作和发布我们需要的报表,报表效果也还不错 不过如果报表数据过大或报表数量过多,打开及查看报表感觉可能就是另外一回事了 好在Reporting ...

  3. Force.com微信开发系列(五)自定义菜单进阶及语音识别

    在上文里我们介绍了如何通过Force.com平台里为微信账号添加自定义菜单,本文里我们将进一步介绍如何查询菜单以及删除菜单的相关知识,最后会介绍微信平台如何进行语音识别的相关技术. 查询菜单 与创建菜 ...

  4. 【读书笔记】iOS-NSData

    Cocoa为我们提供了NSData类,该类包装了大量字节,你可以获得数据的长度和指向字节起始位置的指针,因为NSData是一个对象,适用于常规的内存管理行为.因此,如果将数据块传递给一个函数或方法,可 ...

  5. Sublime Text 最佳插件列表(转)

    Package Control 安装方法 首先通过快捷键 ctrl+` 或者 View > Show Console 打开控制台,然后粘贴相应的 Python 安装代码. Sublime Tex ...

  6. IOS GCD 浅析

     一.简单介绍 1.队列的类型:      1.1主队列:main queue 主线程队列,更新UI的操作.是一个串行的队列,串行队列每次只处理一个任务.      1.2系统创建的并发队列:glob ...

  7. C语言的判断语句

    // // main.c // homeWork1222 //// #include <stdio.h> int main(int argc, const char * argv[]) { ...

  8. UISearchBar改变搜索框的高度

    系统的searchBar UISearchBar的中子控件及其布局 UIView(直接子控件) frame 等于 searchBar的bounds,view的子控件及其布局 UISearchBarBa ...

  9. SQL之 CAST 和 CONVERT

    原文来自于: http://bbs.csdn.net/topics/330251394 CAST 和 CONVERT将某种数据类型的表达式显式转换为另一种数据类型.CAST 和 CONVERT 提供相 ...

  10. 主流Web服务器一览

    概念Web服务器是可以向发出请求的浏览器提供文档的程序. 1.服务器是一种被动程序:只有当Internet上运行在其他计算机中的浏览器发出请求时,服务器才会响应. 2.最常用的Web服务器是Apach ...