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 ...
随机推荐
- RxJava的使用
前言 RxJava及RxAndroid比较详细的介绍可以参考该文档<给 Android 开发者的 RxJava 详解> 基本介绍 ReactiveX 及 RxJava使用大部分来自和参考& ...
- ios项目开发(天气预报项目):通过经纬度获取当前城市名称
1 . 在项目里加入� CoreLocation.framework 2 .在 .h 文件输入例如以下: 1.#import <CoreLocation/CLLocation.h> ...
- 一个 Android 任务队列的实现
最近在做Android项目时遇到这样一个问题:客户端向服务器请求数据,而在网络信号太差的情况下,数据迟迟不到,甚至丢失.服务器为了解决这个问题做了频繁的重发,android 客户端就会收到很多不想要的 ...
- Android下实现GPS定位服务
1.申请Google API Key,参考前面文章 2.实现GPS的功能需要使用模拟器进行经纬度的模拟设置,请参考前一篇文章进行设置 3.创建一个Build Target为Google APIs的项目 ...
- IE jquery mouseenter,mouseover超奇葩问题
做了个项目,结构很简单 <div class="index-main" data-url="./img/index_default.jpg"> &l ...
- 深入学习block
首先,什么是block?block其实就是一个代码块,把你想要执行的代码封装在这个代码块里,等到需要的时候再去调用.那block是OC对象吗?答案是肯定的. 做一道很简单的关于block的测试题: i ...
- 正则表达式 之 C#后台应用
正则表达式在.Net就是用字符串表示,这个字符串格式比较特殊,无论多么特殊,在C#语言看来都是普通的字符串,具体什么含义由Regex类内部进行语法分析. Regex 类 存在于 System.Text ...
- oracle11g密码大小写敏感问题
密码大小写敏感是Oracle 11g数据库默认的一个新特性,数据库配置助手(DBCA)在创建数据库期间允许你将这个设置返回到11g以前的功能. SEC_CASE_SENSITIVE_LOGON初始化参 ...
- Swift数据类型
1.Swift中常用数据类型:首字母大写 Int.Float.Double.Bool.Character.String Array.Dictionary.元组类型(Tuple).可选类型Optiona ...
- JAVA_Reflection1
package com.qf.reflection1; import java.lang.reflect.Constructor; import java.lang.reflect.Field; im ...