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. 一些好用的nginx第三方模块

    一些好用的nginx第三方模块 转自;http://macken.iteye.com/blog/1963301  1.Development Kit https://github.com/simpl/ ...

  2. cocos2d-x ClippingNode

    转自:http://blog.csdn.net/bill_man/article/details/8498424 可以根据一个模板切割图片的节点--CCClippingNode.这个类提供了一种不规则 ...

  3. js 类似php中foreach的方法

    参考下面实例 <script>var arr =  {    'a' : '111111',    'b' : '222222',    'c' : '333333'};for(var k ...

  4. SmoothProgressBar

    https://github.com/castorflex/SmoothProgressBar

  5. [React Native + Firebase] React Native: Real time database with Firebase -- setup & CRUD

    Install: npm i --save firebase // v3.2.1 Config Firebase: First we need to require Firebase: import ...

  6. (转)Dependency Walker使用说明

    在Windows世界中,有无数块活动的大陆,它们都有一个共同的名字——动态链接库.现在就让我们走进这些神奇的活动大陆,找出它们隐藏已久的秘密吧! 初窥门径:Windows的基石 随便打开一个系统目录, ...

  7. HttpWebRequest 模拟登录响应点击事件(分享自己用的HttpHelper类)

    平时也经常采集网站数据,也做模拟登录,但一般都是html控件POST到页面登录:还没有遇到用户服务器控件button按钮点击事件登录的,今天像往常一样POST传递参数,但怎么都能登录不了:最后发现还有 ...

  8. centos nginx和tomcat 通过反向代理生成想要的nexus网址

    研究背景: 最近一直在研究maven nexus 私服,所以想在自己带老笔记本上搭建一个私服,看到网上很多私服都有自己带域名,所以想在搭建过程中通过修改host 生成想要带域名 成功截图: 操作步骤: ...

  9. JForum 2.19源码部署到eclipse

    前两天在研究免费论坛,通过oschina和相关的文档查阅,最终选择了jforum,首先他是java写的,其次方便二次开发,而且有些论坛的源码都已经不在维护了,jforum最近几个月还是有更新的,但是从 ...

  10. 关于Eclipse中的开源框架EMF(Eclipse Modeling Framework)

    Eclipse项目本身可以划分为4个主要的子项目:Equinox,平台,Java开发工具(Java Development Tools,JDT)和插件开发环境(Plug-in Development ...