Common Subsequence

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

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
 
题目大意:
     输入两个字符串,输出这两个字符串的最长公共子序列长度。
解题思路:
     最长公共子序列模板题,算法详解:http://www.cnblogs.com/yoke/p/6686898.html
 

 #include <stdio.h>
#include <string.h> char s1[],s2[];
int x[][]; // 记录最长公共子序列
int LCS()
{
int i,j;
int l1 = strlen(s1); // 计算字符串的长度
int l2 = strlen(s2);
memset(x,,sizeof(x)); // 初始化 过滤掉0的情况 for (i = ; i <= l1; i ++)
{
for (j = ; j <= l2; j ++)
{
if (s1[i-] == s2[j-]) // 相等的情况
// 字符数组是从0开始的 所以这里要减 1
x[i][j] = x[i-][j-]+;
else if(x[i-][j] >= x[i][j-]) // 不相等的时候选择 比较“左边”和“上边”选择较大的
x[i][j] = x[i-][j];
else
x[i][j] = x[i][j-];
}
}
return x[l1][l2];
}
int main ()
{
while (scanf("%s%s",s1,s2)!=EOF)
{
int len = LCS();
printf("%d\n",len);
}
return ;
}

hdu 1159 Common Subsequence(LCS)的更多相关文章

  1. HDU 1159 Common Subsequence(裸LCS)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1159 Common Subsequence Time Limit: 2000/1000 MS (Jav ...

  2. hdu 1159:Common Subsequence(动态规划)

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

  3. HDU 1159 Common Subsequence (dp)

    题目链接 Problem Description A subsequence of a given sequence is the given sequence with some elements ...

  4. HDU 1159——Common Subsequence(DP)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=1159 题解 #include<iostream> #include<cstring> ...

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

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1159 Common Subsequence Time Limit: 2000/1000 MS (Jav ...

  6. HDU 1159 Common Subsequence:LCS(最长公共子序列)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1159 题意: 求最长公共子序列. 题解: (LCS模板题) 表示状态: dp[i][j] = max ...

  7. 题解报告:hdu 1159 Common Subsequence(最长公共子序列LCS)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1159 Problem Description 给定序列的子序列是给定的序列,其中有一些元素(可能没有) ...

  8. hdu 1159 Common Subsequence (dp乞讨LCS)

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

  9. HDU - 1159 Common Subsequence (最长公共子序列)

    A subsequence of a given sequence is the given sequence with some elements (possible none) left out. ...

随机推荐

  1. vue-cli 3.5 解决 typescript cannot find file 问题。

    版本: "ts-loader": "^3.5.0","typescript": "^3.3.4000", "v ...

  2. 利用Python实现倒序任意整数

    这是很早以前学习C时候做过的一个练习题,题目的要求大概是把用户输入的三位数倒序输出,比如说用户输入123,然后程序应该输出的结果是321.如果遇到用户输入100,那么程序应该输出1.然后我给扩展一下, ...

  3. CDH6安装文档

    1.准备工作 1.1 环境 centos7.jdk8.mysql5.7.python2.7.CDH6 1.2文件下载 1.2.1 cloudmanger地址 https://archive.cloud ...

  4. HDFS 删除大量文件

    hdfs dfs -find <path> | xargs -n 1000 hdfs dfs -rm -skipTrash

  5. System Verilog基础(一)

    学习文本值和基本数据类型的笔记. 1.常量(Literal Value) 1.1.整型常量 例如:8‘b0 32'd0 '0 '1 'x 'z 省略位宽则意味着全位宽都被赋值. 例如: :] sig1 ...

  6. 【Python】端口扫描脚本

    0x00   使用模块简介 1.optparse模块 选项分析器,可用来生成脚本使用说明文档,基本使用如下: import optparse #程序使用说明 usage="%prog -H ...

  7. apache的应用(发布目录,黑白名单,虚拟主机,PHP-cgi支持,正向代理,https加密,)

    [root@apache1 ~]# yum install httpd -y [root@apache1 ~]# cd /var/www/html/   进入默认发布目录 [root@apache1 ...

  8. Storm个人学习总结

    https://www.jianshu.com/p/c7fba7d6a24d https://www.cnblogs.com/peak-c/p/6297794.html https://blog.cs ...

  9. $bzoj1027-JSOI2007$ 合金 计算几何 最小环

    题面描述 某公司加工一种由铁.铝.锡组成的合金.他们的工作很简单.首先进口一些铁铝锡合金原材料,不同种类的原材料中铁铝锡的比重不同.然后,将每种原材料取出一定量,经过融解.混合,得到新的合金.新的合金 ...

  10. C# LINQ学习笔记

    LINQ,语言集成查询: LINQ TO SQL,同EF,NHibernate一样,也是一种ORM框架: 1. 入门应用示例: static public void LinqBasic() { var ...