1808:公共子序列

总时间限制: 
1000ms

内存限制: 
65536kB
描述
我们称序列Z = < z1, z2, ..., zk >是序列X = < x1, x2, ..., xm >的子序列当且仅当存在 严格上升 的序列< i1, i2, ..., ik >,使得对j = 1, 2, ... ,k, 有xij = zj。比如Z = < a, b, f, c > 是X = < a, b, c, f, b, c >的子序列。

现在给出两个序列X和Y,你的任务是找到X和Y的最大公共子序列,也就是说要找到一个最长的序列Z,使得Z既是X的子序列也是Y的子序列。

输入
输入包括多组测试数据。每组数据包括一行,给出两个长度不超过200的字符串,表示两个序列。两个字符串之间由若干个空格隔开。
输出
对每组输入数据,输出一行,给出两个序列的最大公共子序列的长度。
样例输入
abcfbc         abfcab
programming contest
abcd mnp
样例输出
4
2
0
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int N=;
int n,m,f[N][N];char x[N],y[N];
int main(){
while(~scanf("%s%s",x+,y+)){
n=strlen(x+);m=strlen(y+);
memset(f,,sizeof f);
for(int i=;i<=n;i++){
for(int j=;j<=m;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[n][m]);
}
return ;
}

1808:公共子序列 即POJ 1458 Common Subsequence的更多相关文章

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

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

  2. LCS POJ 1458 Common Subsequence

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

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

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

  4. POJ 1458 Common Subsequence 【最长公共子序列】

    解题思路:先注意到序列和串的区别,序列不需要连续,而串是需要连续的,先由样例abcfbc         abfcab画一个表格分析,用dp[i][j]储存当比较到s1[i],s2[j]时最长公共子序 ...

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

    题目链接Time Limit: 1000MS Memory Limit: 10000K Total Submissions: Accepted: Description A subsequence o ...

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

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

  7. POJ 1458 Common Subsequence 最长公共子序列

    题目大意:求两个字符串的最长公共子序列 题目思路:dp[i][j] 表示第一个字符串前i位 和 第二个字符串前j位的最长公共子序列 #include<stdio.h> #include&l ...

  8. POJ 1458 Common Subsequence (DP+LCS,最长公共子序列)

    题意:给定两个字符串,让你找出它们之间最长公共子序列(LCS)的长度. 析:很明显是个DP,就是LCS,一点都没变.设两个序列分别为,A1,A2,...和B1,B2..,d(i, j)表示两个字符串L ...

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

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

随机推荐

  1. 通过Forms身份验证设置不同页面的访问权限

    使用Forms身份验证的时候,如果允许注册页面可以匿名用户访问,其他所有页面只允许注册用户访问,我们可以如下设置web.config文件来达到上述的效果: 1.在“system.web”节点下,添加登 ...

  2. C#:Application操作(待补充)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  3. 硬盘Raid

    一.raid什么意思? RAID是“Redundant Array of Independent Disk”的缩写,raid什么意思了?说白了,中文翻译过来通俗的讲就是磁盘阵列的意思,也就是说RAID ...

  4. blender, merge顶点

    选择Edit Mode:,和vertex select: 同时选中两个要merge的顶点(同时选中多个顶点:http://www.cnblogs.com/wantnon/p/4526573.html) ...

  5. ffff表单提交的那点事

    一.关于application/x-www-form-urlencoded等字符编码的解释说明 在Form元素的语法中,EncType表明提交数据的格式 用 Enctype 属性指定将数据回发到服务器 ...

  6. CXSprite.cpp文件

    #include "XSprite.h" CXSprite::CXSprite(void) { m_strPic.clear(); } CXSprite::~CXSprite() ...

  7. django 将model转换为字典

    from django.forms.models import model_to_dict from projects.models import ProjectInformation site = ...

  8. scala,spark练习题提高

    1.求每家公司有哪些产品 val arr3 = List("Apache" -> "Spark", "Apache" -> &q ...

  9. scala 测试类

    class NetworkUtilTest extends FunSuite with Matchers { test("testIp2Int") { val ip = Netwo ...

  10. man page用法

    通过man man可查看man page的具体用法. 1   Executable programs or shell commands       2   System calls (functio ...