OpenJudge/Poj 1458 Common Subsequence
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 mnpSample Output
4
2
0Source
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的更多相关文章
- LCS POJ 1458 Common Subsequence
题目传送门 题意:输出两字符串的最长公共子序列长度 分析:LCS(Longest Common Subsequence)裸题.状态转移方程:dp[i+1][j+1] = dp[i][j] + 1; ( ...
- POJ 1458 Common Subsequence(LCS最长公共子序列)
POJ 1458 Common Subsequence(LCS最长公共子序列)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?c ...
- POJ 1458 Common Subsequence(最长公共子序列LCS)
POJ1458 Common Subsequence(最长公共子序列LCS) http://poj.org/problem?id=1458 题意: 给你两个字符串, 要你求出两个字符串的最长公共子序列 ...
- POJ 1458 Common Subsequence (动态规划)
题目传送门 POJ 1458 Description A subsequence of a given sequence is the given sequence with some element ...
- Poj 1458 Common Subsequence(LCS)
一.Description A subsequence of a given sequence is the given sequence with some elements (possible n ...
- poj 1458 Common Subsequence
Common Subsequence Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 46387 Accepted: 19 ...
- poj 1458 Common Subsequence【LCS】
Common Subsequence Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 43132 Accepted: 17 ...
- (线性dp,LCS) POJ 1458 Common Subsequence
Common Subsequence Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 65333 Accepted: 27 ...
- POJ - 1458 Common Subsequence DP最长公共子序列(LCS)
Common Subsequence A subsequence of a given sequence is the given sequence with some elements (possi ...
随机推荐
- 匿名内部类new Runnable()
匿名内部类(Anonymous Inner Class),在创建实例的同时给出类的定义,所有这些在一个表达式中完成. Java code? 1 2 3 4 Runnable rn = new Runn ...
- MySQL to Redis
[TOC] 简介 使用mysql2redis可以非常便捷的将mysql中的数据导出到redis中去, 通常是需要一个select语句即可实现. 软件安装 // 安装apr + apr-util $ w ...
- C _数据结构 _线性表的顺序存储
#ifndef __MY_SEQLIST_H__ #define __MY_SEQLIST_H__ typedef void SeqList; typedef void SeqListNode; // ...
- PAT 1013
1013. Battle Over Cities (25) It is vitally important to have all the cities connected by highways i ...
- JavaScript,Java,php的区分大小写问题
JavaScript 对大小写敏感. JavaScript 对大小写是敏感的.JavaScript属于弱类型语言 当编写 JavaScript 语句时,请留意是否关闭大小写切换键. 函数 getEle ...
- String使用equals方法和==分别比较的是什么?
equals方法和==的区别 首先大家知道,String既可以作为一个对象来使用,又可以作为一个基本类型来使用.这里指的作为一个基本类型来使用只是指使用方法上的,比如String s = &quo ...
- IIS 之 启用日志记录
如何为网站启用日志记录或 在 Microsoft Internet Information Services (IIS) 6.0 中,在 IIS 5.0 中,并在 IIS 4.0 中的FTP 站点.可 ...
- php笔记02:整型细节说明
1.php的一个整数可以是十进制,也可以是八进制和十六进制: 比如:$a=0123; //八进制 $a=0x1A; //十六进制 2.php的整数都是有符号的数(java也是只有有符号数) 3.在ph ...
- 在IOS中 NSRange类详解
NSRange的定义 typedef struct _NSRange { NSUInteger location; NSUInteger length; } NSRange; NSRange是一个结构 ...
- JAVA_Gson
package com.qf.mobiletrain01; import java.util.List; import com.google.gson.Gson; import com.google. ...