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 ...
随机推荐
- ECSHOP在线手册布局参考图--登录/注册页 user_passport.dwt
A.会员登录框 1,设置方法 自带模块 2,代码相关 user_passport.dwt 中 <div class="usBox_1 f_l"> <div ...
- 【转】移动前端手机输入法自带emoji表情字符处理
http://blog.csdn.net/binjly/article/details/47321043 今天,测试给我提了一个BUG,说移动端输入emoji表情无法提交.很早以前就有思考过,手机输入 ...
- 打开已存在 Android项目及常见的问题
Eclipse 打开已存在 Android项目及常见的问题 1. 点击菜单“File”-- "Import",会弹出 Import 对话框: 2, 选择“General ...
- 封装的分页jq
(function ($) { $.fn.page = function (options) { var defaults = { divid: "pagediv", count: ...
- ADO.Net的小知识(连接数据库)二
上次提到数据库连接有两种形式断开式连接和打开式连接,断开式连接我已经讲解了,下面我来给大家讲解一下打开式连接 (1)引入命名空间:using System.Data.SqlClient; 该语句用于导 ...
- 如何安装SQL Server 2008数据库(带完整图解)
在电脑上安装SQL Server 2008 软件时,经常会遇到各种各样的问题,如何成功的安装SQL Server 2008呢?提供完整过程和图片详解. 工具/原料 电脑一台 软件:sql server ...
- javascript——touch事件
前言 诸如智能手机和平板电脑一类的移动设备通常会有一(capacitive touch-sensitivescreen),以捕捉用户的手指所做的交互.随着移动网络的发展,其能够支持越来越复杂的应用,w ...
- 三个案例带你看懂LayoutInflater中inflate方法两个参数和三个参数的区别
关于inflate参数问题,我想很多人多多少少都了解一点,网上也有很多关于这方面介绍的文章,但是枯燥的理论或者翻译让很多小伙伴看完之后还是一脸懵逼,so,我今天想通过三个案例来让小伙伴彻底的搞清楚这个 ...
- 深入理解计算机系统第二版习题解答CSAPP 2.13
从20世纪70年代末到80年代末,Digital Equipment的VAX计算机是一种非常流行的机型.它没有布尔运算AND和OR指令,只有bis(位设置)和bic(位清除)这两种指令.两种指令的输入 ...
- JavaScript总结3—对象
对象是JavaScript的基本类型,他可以从一个称为原型的对象继承属性,这种原型式继承是JavaScript的核心特征.对对象比较常见的操作有:创建,设置,查找,删除,检测和枚举他的属性.每个对象都 ...