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. ECSHOP在线手册之布局参考图-首页 index.dwt

        A.logo替换 1,设置方法 后台商店设置里,上传logo就行,注意logo的名称必须是logo.gif 2,代码相关 page_header.lbi 中 <a href=" ...

  2. 拼接json示例 json分页并显示所有页码

    <%@ page language="java" import="java.util.*" pageEncoding="gbk"%&g ...

  3. Gitbook安装

    Gitbook安装 Gitbook是从NMP安装的,命令行: $ npm install gitbook -g 安装完之后,你可以检验下是否安装成功: $ gitbook -V 0.4.2 如果你看到 ...

  4. Funambol Developer&#39;s Guide 中 connector development样例的问题

    今天学习Funambol的connector开发,官方文档中的样例有问题. 首先,文档中提供的maven命令不可用: mvn archetype:generate -DarchetypeGroupId ...

  5. MFC——从实现角度分析微云界面

    在云计算时代之风吹来,很多互联网公司都在建云,提出云盘.云储存.云平台.云空间等等,骤然间,天下皆云.云是啥?有用户量,就有云,没有用户量,你的系统,你的云,也就是一朵白云. 最近研究了下微云的界面, ...

  6. windows8 认识及使用

    windows8的一次技术分享. 利用国庆宅家的几天,在跑不动XP的老笔记本上装了win8,嘿,跑的溜溜的,一高兴做个ppt给公司的同事们介绍介绍,随意之作,勿较真抬杠,呵呵. 文件地址:http:/ ...

  7. sessionID和cookie

    一.cookie机制和session机制的区别***************************************************************************** ...

  8. Vs 2008 解决方案的目录结构设置和管理(转)

    http://blog.csdn.net/lcj_cjfykx/article/details/8632459 MS的这个IDE,实在庞杂得恐怖.从大学开始,我就一直用VC的各个版本写程序至今,细细想 ...

  9. 【转】在XCode工程中创建bundle包

    http://www.giser.net/?p=859 Bundle Programming Guide: https://developer.apple.com/library/ios/docume ...

  10. 文件夹添加右键DOS快捷入口

    1.自带的方法 win7: 按住shift键然后右键点击文件夹,菜单里会出现“在此处打开命令窗口”一项,其实就相当于在当前位置打开Dos窗口,这个是系统自带的. winxp: 打开“我的电脑”,点击菜 ...