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. SharePoint部署工具SPSD

    SharePoint Solution Deployer,绝对属于必备的SharePoint工具之一了. 下载,解压这个工具,会有如下的目录(没有Assemblies和DeployGAC.bat)解压 ...

  2. SharedPreference.Editor的apply和commit方法异同

    这两个方法的区别在于: 1. apply没有返回值而commit返回boolean表明修改是否提交成功 2. apply是将修改数据原子提交到内存, 而后异步真正提交到硬件磁盘, 而commit是同步 ...

  3. DownloadManager 的使用

    一.基本概念    1.DownloadManager是Android 2.3A (API level 9) 引入的,基于http协议,用于处理长时间下载. 2.DownloadManager对于断点 ...

  4. 内置对象Clob对从数据库表中取的字符大对象CLOB类型的列值进行读取操作

    package readclobDemo.bao; import java.io.IOException; import java.io.Reader; import java.sql.Clob; i ...

  5. Git基本使用命令

    整理Git的一些基本使用命令.   # 1)克隆代码 boldseas@lian-PC MINGW64 /d/TestGroup $ git clone ssh://git@code.boldseas ...

  6. Effective Java 59 Avoid unnecessary use of checked exceptions

    The burden is justified if the exceptional condition cannot be prevented by proper use of the API an ...

  7. 关于移动端的font和图片的问题

    一.font-family 使用无衬线字体 body { font-family: "Helvetica Neue", Helvetica, STHeiTi, sans-serif ...

  8. SQL基础(2)-约束

    1. 添加主键约束 a.创建表时添加主键(默认系统命名主键) create table pt_ticket_info( id varchar2(50) primary key not null, -- ...

  9. cocos2d-x之加法计算器

    bool HelloWorld::init() { if ( !Layer::init() ) { return false; } Size visibleSize = Director::getIn ...

  10. Spring 下载与安装以及spring 3.2.9 jar包详解

    一.Spring简介  Spring官网改版后,很多项目的完整zip包下载链接已经隐掉了,虽然Spring旨在引导大家用更“高大上”的maven方式来管理所依赖的jar包,但是完全没想到中国的国情,在 ...