题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1159

Common Subsequence

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

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
 
题目大意:求两个串的最长公共子序列长度。
 
解题思路:套用模板。
 
AC代码:
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. char x[], y[];
  8. int b[][], c[][];
  9. void LCS()
  10. {
  11. int i,j;
  12. int len1 = strlen(x);
  13. int len2 = strlen(y);
  14. for (i = ; i <= len1; i ++) b[i][] = ;
  15. for (j = ; j <= len2; j ++) b[][j] = ;
  16.  
  17. for (i = ; i <= len1; i ++)
  18. {
  19. for (j = ; j <= len2; j ++)
  20. {
  21. if (x[i-] == y[j-])
  22. b[i][j] = b[i-][j-] + ;
  23. else
  24. b[i][j] = max(b[i-][j],b[i][j-]);
  25. }
  26. }
  27. printf("%d\n",b[len1][len2]);
  28. }
  29.  
  30. int main ()
  31. {
  32. while (scanf("%s%s",x,y)!=EOF)
  33. {
  34. LCS();
  35. }
  36. return ;
  37. }

hdu 1159 Common Subsequence(最长公共子序列)的更多相关文章

  1. HDU 1159 Common Subsequence 最长公共子序列

    HDU 1159 Common Subsequence 最长公共子序列 题意 给你两个字符串,求出这两个字符串的最长公共子序列,这里的子序列不一定是连续的,只要满足前后关系就可以. 解题思路 这个当然 ...

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

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

  3. C++版 - Lintcode 77-Longest Common Subsequence最长公共子序列(LCS) - 题解

    版权声明:本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C++版 - L ...

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

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

  5. lintcode 77.Longest Common Subsequence(最长公共子序列)、79. Longest Common Substring(最长公共子串)

    Longest Common Subsequence最长公共子序列: 每个dp位置表示的是第i.j个字母的最长公共子序列 class Solution { public: int findLength ...

  6. LCS(Longest Common Subsequence 最长公共子序列)

    最长公共子序列 英文缩写为LCS(Longest Common Subsequence).其定义是,一个序列 S ,如果分别是两个或多个已知序列的子序列,且是所有符合此条件序列中最长的,则 S 称为已 ...

  7. LCS修改版(Longest Common Subsequence 最长公共子序列)

    题目描述 作为一名情报局特工,Nova君(2号)有着特殊的传达情报的技巧.为了避免被窃取情报,每次传达时,他都会发出两句旁人看来意义不明话,实际上暗号已经暗含其中.解密的方法很简单,分别从两句话里删掉 ...

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

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

  9. LCS(Longest Common Subsequence)最长公共子序列

    最长公共子序列(LCS)是一个在一个序列集合中(通常为两个序列)用来查找所有序列中最长子序列的问题.这与查找最长公共子串的问题不同的地方是:子序列不需要在原序列中占用连续的位置 .最长公共子序列问题是 ...

  10. PKU 1458 Common Subsequence(最长公共子序列,dp,简单)

    题目 同:ZJU 1733,HDU 1159 #include <stdio.h> #include <string.h> #include <algorithm> ...

随机推荐

  1. vue 移动端,页面左右页面切换效果(切换过程中会出现白屏效果,布吉岛怎么优化,后来就发布前就弃用了)

    <transition name="left"> <router-view v-if="getCms" class="Router& ...

  2. Vue.js 使用注意事项

    Vue.js 使用注意事项 1 过滤器主要用于简单的文本转换,如果要实现复杂的数据变换,应使用计算属性 指令的使用 v-bind基本用于HTML元素上的属性,如id.class.href.src等 v ...

  3. 制作kvm镜像、格式转换

    2018-12-25 制作kvm镜像(以centos 7 为例) 执行创建虚拟机命令 virt-install --name centos7_kvm --memory --vcpus= --disk ...

  4. C#串口通讯中常用的16进制的字节转换

    1.对于通讯协议的十六进制数值进行简单转换 //二进制转十进制Console.WriteLine("二进制 111101 的十进制表示: "+Convert.ToInt32(&qu ...

  5. 一些学习比较好的网站,及es6学习好网站,前端用的相关库,及知道的插件

    图形可视化:d3js  echarts https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects ...

  6. redis3.0 cluster功能介绍

    edis从3.0开始支持集群功能.redis集群采用无中心节点方式实现,无需proxy代理,客户端直接与redis集群的每个节点连接,根据同样的hash算法计算出key对应的slot,然后直接在slo ...

  7. Hibernate各种查询操作(二)

    一.QBC的查询方式 使用QBC不在需要写hql语句,而是使用criteria对象的各种方法来实现. 1.查询所有 //使用QBC方式查询所有 @Test public void test11(){ ...

  8. wcf 登录认证 angular 认证重定向

    自定义认证管理器,分为两级:1.登陆认证.2.权限认证.权限主要是用户.角色.角色用户关系.功能(系统资源).角色功能关系,5部分决定用户的权限(视图). 两层认证都通过后,更新session的最新交 ...

  9. [转]微信小程序登录数据解密以及状态维持

    本文转自:http://www.cnblogs.com/cheesebar/p/6689326.html 学习过小程序的朋友应该知道,在小程序中是不支持cookie的,借助小程序中的缓存我们也可以存储 ...

  10. JavaScript的六种数据类型

      JavaScript数据类型有六种:number.string.boolean.null.undefined.object