hdu1159Common Subsequence(动态规划)
Common Subsequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 49137 Accepted Submission(s): 22632
The program input is from a text file. Each data set in the file contains two strings representing the given sequences. The sequences are separated by any number of white spaces. The input data are correct. 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.
题意:求两个字符串的最长公共子序列,一个经典问题
当a[i]==b[j]时 dp[i][j]=dp[i-1][j-1]+1
当a[i]!=b[j]时 dp[i][j]=max(dp[i][j-1],dp[i-1][j])
#include<bits/stdc++.h>
using namespace std;
char a[],b[];
int dp[][];
int main() { while(~scanf("%s %s",a+,b+)) {
memset(dp,,sizeof(dp)); int maxx=-;
int alen=strlen(a+);
int blen=strlen(b+);
for(int i=; i<=alen; i++) {
for(int j=; j<=blen; j++) {
if(a[i]==b[j])dp[i][j]=dp[i-][j-]+;
else dp[i][j]=max(dp[i-][j],dp[i][j-]);
//maxx=max(maxx,dp[i][j]);
}
}
printf("%d\n",dp[alen][blen]);
memset(a,'\0',sizeof(a));
memset(b,'\0',sizeof(b));
}
return ;
}
hdu1159Common Subsequence(动态规划)的更多相关文章
- hdu1159Common Subsequence——动态规划(最长公共子序列(LCS))
Problem Description A subsequence of a given sequence is the given sequence with some elements (poss ...
- HDU 1159 Common Subsequence 动态规划
2017-08-06 15:41:04 writer:pprp 刚开始学dp,集训的讲的很难,但是还是得自己看,从简单到难,慢慢来(如果哪里有错误欢迎各位大佬指正) 题意如下: 给两个字符串,找到其中 ...
- POJ 2127 Greatest Common Increasing Subsequence -- 动态规划
题目地址:http://poj.org/problem?id=2127 Description You are given two sequences of integer numbers. Writ ...
- HDOJ 1423 Greatest Common Increasing Subsequence -- 动态规划
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1423 Problem Description This is a problem from ZOJ 2 ...
- HDU1159-Common Subsequence
描述: A subsequence of a given sequence is the given sequence with some elements (possible none) left ...
- 算法:Common Subsequence(动态规划 Java 最长子序列)
Description A subsequence of a given sequence is the given sequence with some elements (possible non ...
- HDU 1423 Greatest Common Increasing Subsequence ——动态规划
好久以前的坑了. 最长公共上升子序列. 没什么好说的,自己太菜了 #include <map> #include <cmath> #include <queue> ...
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
随机推荐
- JavaScript小游戏--2048(PC端)
1.初始化棋局 $(document).ready(function() { prepare_for_mobile(); //适配移动端 new_game(); }); 2.开始新游戏 functio ...
- 2019.1.3 Mac安装免费版StarUml3.0.2 &&&Xmind思维导图 &&Google浏览器***版
下载StarUml http://staruml.io/ 好像需要FQ 附赠一个 链接:https://pan.baidu.com/s/1_pa9LwopowhOTum5g89zZQ 密码:fxtc ...
- Dropbox的CEO在MIT的毕业演讲
这是我今天看到的一个演讲,个人觉得和乔老大在斯坦佛的毕业演讲有异曲同工之妙,我也觉得对工科的我们很有启发意义,就此转载,希望与君共勉. 编者注:本篇文章基于Drew Houston 在 MIT 毕业典 ...
- spring+jdbc+template+transaction实现
使用spring和jdbc模板事务实现 1.创建实体类: Role package com.wbg.sjt.entity; public class Role { private int id; pr ...
- [转]ASP.NET母版页中对控件ID的处理
一.问题提出 由于总体排版和设计的需要,我们往往创建母版页来实现整个网站的统一性,最近我由于统一性的需要,把原来整个项目单独的页面全部套用了母版页.但是出现了一个错误……在我的Blog中记录一下,方便 ...
- Xcode 7.0 SDK(Software Development Kit) 及 Sandbox(沙盒) 存放路径
1. Sandbox(沙盒) 存放路径 我的硬盘/Users/wj121/Library/Developer/CoreSimulator/Devices/879D7E35-BE50-4620-97E1 ...
- AOP切点切面内容
一.实现接口MethodBeforeAdvice该拦截器会在调用方法前执行 实现接口 AfterReturningAdvice该拦截器会在调用方法后执行 ...
- JS n秒后自动跳转实例
<p><a href="<?php echo base_url();?>usercenter/index" id="message" ...
- js判断值是不是全是数字
if(isNaN(value)){ 不是数字 }else{ 全是数字 }
- 管理Django1.9静态文件static
管理Django1.9静态文件static 网站通常需要增加图片.JavaScript.或者CSS等文件提供服务.在Django中,我们把这些文件称为“静态文件”(static files).Djan ...