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. ...
随机推荐
- 一张图解释 implicit
- Fidder学习基础(二)
一. 巧用代理抓包. 首页,需设置Tools——>Fiddler Options——>Connectons,维护代理端口及允许其他设备连接. 这里,需要注意的是端口配置不能重复,抓包代理设 ...
- mybatis全局配置文件
一.properties:引入外部配置文件 1.resource :引入类路径下的全局配置文件,例如:<properties resource="conf/dbconfig.prope ...
- Gradle Goodness: Adding Tasks to a Predefined Group
In Gradle we can group related tasks using the group property of a task. We provide the name of our ...
- c++中如 <类名 类名::对象> 是什么意思
CComplex CComplex::add(CComplex &x) (这一句 不懂为何 类名 类名::对象) { CComplex y(real+x.real,image+x.image) ...
- Unity3D Errors And Fix
Author Error: Shader warning in 'Custom/ShowAnimation': Not enough temporary registers, needs 9 (com ...
- [开源]JSON文本格式化工具(简码万能助手开源扩展程序)
现在的网站大多都是使用json进行API式前后端数据交互, 有时抓包得到的是一串没格式化的JSON文本, 不太方便分析, 所以我自行写了个开源扩展程序, 可以方便地格式化JSON文本. 当然,你也 ...
- df du sync
df命令用来检查linux系统的磁盘空间占用情况 df [选项] -h:以容易理解的格式输出文件系统分区占用情况,如32KB,120MB,60GB -k:以KB大小单位输出文件系统分区占用情况 -m: ...
- 19-3-6Python中字典的解释、使用、嵌套
一.字典 为什么学字典: 列表的缺点: 1.列表如果存储的数据比较多,那么他的查询速度相对慢. 2.列表存储的数据关联性不强. 字典是什么: Python基础数据类型之一:字典. Python中唯一的 ...
- Jquery拼图
Jquery代码 <script> $(function () { $("td").click(function () { var img = $(this).prop ...