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. ...
随机推荐
- web项目继承ServletContainerInitializer进行访问HttpServlet(WebServlet)
java使用web项目不需要加web.xml 配置javax.servlet.ServletContainerInitializer 1.在src目录创建META-INF,META-INF目录下创建s ...
- PAT——1055. 集体照 (比较comparable和comparator的区别)
拍集体照时队形很重要,这里对给定的N个人K排的队形设计排队规则如下: 每排人数为N/K(向下取整),多出来的人全部站在最后一排: 后排所有人的个子都不比前排任何人矮: 每排中最高者站中间(中间位置为m ...
- nodejs中如何连接mysql
nodejs中如何连接mysql,下面给出一个小Demo. 第一步安装mysql模块npm install mysql 第二步导入mysql模块var mysql = require('mysql') ...
- HIDU 2094
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2094 产生冠军 Time Limit: 1000/1000 MS (Java/Others) M ...
- 第20章 USART—串口通讯
本章参考资料:<STM32F76xxx参考手册>USART章节. 学习本章时,配合<STM32F76xxx参考手册>USART章节一起阅读,效果会更佳,特别是涉及到寄存器说明的 ...
- ASP.NET WebApi 中使用swagger 构建在线帮助文档
1 在Visual Studio 中创建一个Asp.NET WebApi 项目,项目名:Com.App.SysApi(本例创建的是 .net 4.5 框架程序) 2 打开Nuget 包管理软件,查 ...
- linux mysql命令行查看显示中文
linux 命令行查看mysql的库字符集是utf8,查询某个表时,仍然是显示不了中文, 之后使用了命令 mysql>set names utf8;就可以正常显示中文了. 如何才更好的使mys ...
- 商业化IM 客户端设计---Message模型
在IM开发中,一个问题是怎么管理传输,包括处理消息发送,消息接受和怎么转发等等,就是上一篇文章提到的IMService扮演的角色.另一个问题就是传输的具体数据是怎么定义的,既包括业务数据(文字,语音, ...
- 系统优化怎么做-JVM优化之开篇
大家好,这里是「聊聊系统优化 」,并在下列地址同步更新 博客园:http://www.cnblogs.com/changsong/ 知乎专栏:https://zhuanlan.zhihu.com/yo ...
- DZNSegmentedControl和XLForm联合使用
前言: 可能我还没有掌握IOS开发的精髓, 总感觉写ios代码像调bug, 任何一个功能开发完成之后总会有莫名其妙的问题, 最终这些问题很大概率会归结为"系统特性". 正文: 问题 ...