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. scrapyd 参考(https://www.jianshu.com/p/2a189127901a)

    一    Scrapyd简介 Scrapyd 是一个用来部署和运行 Scrapy 项目的应用,由 Scrapy 的开发者开发.其可以通过一个简单的 Json API 来部署(上传)或者控制你的项目. ...

  2. 包子凑数(dp思想)

    问题描述: 小明几乎每天早晨都会在一家包子铺吃早餐.他发现这家包子铺有N种蒸笼,其中第i种蒸笼恰好能放Ai个包子.每种蒸笼都有非常多笼,可以认为是无限笼.每当有顾客想买X个包子,卖包子的大叔就会迅速选 ...

  3. 使用Maven运行测试提示Module sdk 1.5的解决方法

    解决方法: 1. 配置Project Structure 2. 在MAVEN_HOME/conf/setting.xml中添加profile 3. 在Maven项目的pom.xml文件里添加标签 三种 ...

  4. iview 之 穿梭框 transfer

    概述 双栏穿梭选择框,常用于将多个项目从一边移动到另一边. 说明 Transfer 组件主要基于以下四个 API 来使用: :data:总体数据,数组,每项为一个对象,且必须含有 key 值,组件基于 ...

  5. dsad

    dasdas dasdas dasdas dasdas

  6. windows 下创建 sqlite 数据库

    说明:windows 下执行创建 sqlite 数据库命令后数据库文件不会马上生成,需要创建表以后才会生成. 1.将 sqlite3.exe 文件放在任何位置(如放在 d:\tools )2.在 CM ...

  7. Full Text Search 实现Sort的实现方案

    CREATE TABLE dbo.pageStore( ID int NOT NULL, StoreName varchar(50) NULL, OwnerOccupation varchar(50) ...

  8. Robot Framework(Databaselibrary库操作)

    1.安装 DatabaseLibrary 库 DatabaseLibrary 下载地址:https://pypi.python.org/pypi/robotframework-databaselibr ...

  9. python+selenium的搭建过程

    搭建步骤 1.第一步没啥好说的,肯定是先安装python 下载地址:http://download.csdn.net/detail/intel80586/4297269 全部默认安装即可. 安装完毕后 ...

  10. sencha touch SortableList 的使用

    转: sencha touch 2.3 多了一个  SortableList plugin, 可实现 list item 的拖动交换 Ext.require('Ext.plugin.SortableL ...