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. 命令提示符下的WQL

    WQL就是英文WMI Query Language的缩写,就是说wmic这个命令支持简单的一些SQL查询,我们以实例来讲解他的部分用法,这个命令过于强大,因此以下只是该命令的冰山一角. 列出本地连接的 ...

  2. SQL数据库Truncate的相关用法

    数据库中 Truncate的用法:这个是删除表中的所有数据语法是 Truncate Table tablename他与delete的区别在于1 delete 可以有条件的删除 而truncate 是删 ...

  3. 微信 vue中使用video.js播放m3u8视频,解决安卓自动全屏的问题。

    最近一个项目中需要在微信中播放m3u8格式的视频,刚开始用了 vue-video-player 这个插件,在IOS手机体验良好,本以为完事了, 结果安卓手机一点播放就自动全屏,心态略崩.查了资料说是安 ...

  4. java centos7配置查看jdk环境变量

    [root@bogon java-1.8.0-openjdk-1.8.0.212.b04-0.el7_6.x86_64]# which java/usr/bin/java[root@bogon jav ...

  5. Delphi导出word

    //导出Wordprocedure TFrm_Computing.ExportWord;varwordApp, WordDoc, WrdSelection, wrdtable, wrdtable1, ...

  6. Apache和Tomcat的整合过程(转载)

    一 Apache与Tomcat比较联系 apache支持静态页,tomcat支持动态的,比如servlet等. 一般使用apache+tomcat的话,apache只是作为一个转发,对jsp的处理是由 ...

  7. 案例19-页面使用ajax显示类别菜单

    1 版本一 版本只能在首页显示类别,当切换到了其它页面就不会显示 1 web层IndexServlet代码 package www.test.web.servlet; import java.io.I ...

  8. idea开发环境中maven控制台乱码解决

    在pom文件中加入 红色那行, <properties>        <project.build.sourceEncoding>UTF-8</project.buil ...

  9. ubuntu16上安装openJDK.md

    ubuntu16上安装openJDK.md 环境 操作系统:ubuntu 16.04.2 LTS 安装 当你不需要安装oracle的JDK时,使用openJDK,安装就比较方便. sudo apt-g ...

  10. 面试题目: 获取服务器IP和客户端IP

    [面试题目] 怎么获取服务器IP和客户端IP地址? I. PHP获取客户端IP, 可通过下面系统变量 1. $_SERVER['Remote_Addr'] 2. $_SERVER['HTTP_CLIE ...