1.链接地址:

http://poj.org/problem?id=1458

http://bailian.openjudge.cn/practice/1458/

2.题目:

Common Subsequence
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 35411   Accepted: 14080

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.

Input

The program input is from the std input. Each data set in the input contains two strings representing the given sequences. The sequences are separated by any number of white spaces. The input data are correct.

Output

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

Source

3.思路:

4.代码:

 #include "stdio.h"

 //#include "stdlib.h"

 #include "string.h"

 #define N 1000

 char a[N],b[N];

 int c[N+][N+];

 int dp(int lena,int lenb)

 {

     int i,j;

     for(i=;i<=lena;i++) {c[i][]=;}

     for(j=;j<=lenb;j++) {c[][j]=;}

     for(i=;i<=lena;i++)

     {

        for(j=;j<=lenb;j++)

        {

            if(a[i-] == b[j-]) {c[i][j]=c[i-][j-]+;}

            //if(i==1 && j==1){printf("%c %c\n",a[0],b[0]);}

            else { c[i][j]=(c[i][j-]>c[i-][j])?c[i][j-]:c[i-][j]; }

            //printf("%c %c %d\n",a[i-1],b[j-1],c[i][j]);

        }

     }

     return c[lena][lenb];

 }

 int main()

 {

     int i,j;

     while(scanf("%s%s",a,b) != EOF)

     {

        printf("%d\n",dp(strlen(a),strlen(b)));

        //for(i=0;i<strlen(a);i++){for(j=0;j<strlen(b);j++){printf("%d ",c[i][j]);}printf("\n");}

     }

     //system("pause");

     return ;

 }

OpenJudge/Poj 1458 Common Subsequence的更多相关文章

  1. LCS POJ 1458 Common Subsequence

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

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

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

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

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

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

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

  5. Poj 1458 Common Subsequence(LCS)

    一.Description A subsequence of a given sequence is the given sequence with some elements (possible n ...

  6. poj 1458 Common Subsequence

    Common Subsequence Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 46387   Accepted: 19 ...

  7. poj 1458 Common Subsequence【LCS】

    Common Subsequence Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 43132   Accepted: 17 ...

  8. (线性dp,LCS) POJ 1458 Common Subsequence

    Common Subsequence Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 65333   Accepted: 27 ...

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

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

随机推荐

  1. hadoop安装详解

    1.hadoop简介 Hadoop是Apache软件基金会旗下的一个开源分布式计算平台.以Hadoop分布式文件系统(HDFS,Hadoop Distributed Filesystem)和MapRe ...

  2. android学习日记09--BitMap操作

    Bitmap android里的图像处理重要的类,支持jpg.png.bmp等格式的图像,BitmapDrawable是封装Bitmap的一个对象,Bitmap实现在android.graphics包 ...

  3. 特殊用途语言特性——默认参数、内联函数和constexptr函数

    1 默认实参 某些函数有这样一些参数,在函数的很多次调用中它们都被赋予一个相同的值,此时,我们把这个反复出现的值称为函数的默认实参.调用含有默认实参的函数时,可以包含该实参,也可以省略该实参. 我们可 ...

  4. combo参数配置_手册

    combotree : 设置为多选框: $('#menu-combotree').combotree({multiple:true}).combotree('loadData', menuListJs ...

  5. 实例源码--ZXing识别条形码和二维码识别源码

      下载源码 技术要点: 1.ZXing库的 使用 2.识别条形码和二 维码 3.自定义视图 4.源码带有非常详 细的中文注释 ...... 详细介绍: 1.ZXing库 ZXing是个很经典的条码/ ...

  6. java_Cookie添加和删除

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, ...

  7. Config

    Config Config App Auth Cache Database Languages Mail Modules Routing Session Config Settings for the ...

  8. XStream将xml文件拼成字符串

      1.引入的包 <dependency> <groupId>com.thoughtworks.xstream</groupId> <artifactId&g ...

  9. 三个案例带你看懂LayoutInflater中inflate方法两个参数和三个参数的区别

    关于inflate参数问题,我想很多人多多少少都了解一点,网上也有很多关于这方面介绍的文章,但是枯燥的理论或者翻译让很多小伙伴看完之后还是一脸懵逼,so,我今天想通过三个案例来让小伙伴彻底的搞清楚这个 ...

  10. Python 基础【第十篇】内置类型

    一.integral 类型 Python提供了两种integral类型,即int(整数)与bool(布尔值). 1.1.整数 整数的相关运算符.函数.数据类型转换 1.1.1.整数的运算符 前面已经讲 ...