HDU 1087 Super Jumping! Jumping! Jumping! (DP+LIS)
题意:给定一个长度为n的序列,让你求一个和最大递增序列。
析:一看,是不是很像LIS啊,这基本就是一样的,只不过改一下而已,d(i)表示前i个数中,最大的和并且是递增的,
如果 d(j) + a[i] > d(i) d(i) = d(j) + a[i] (这是保证和最大),那么怎么是递增呢?很简单嘛,和LIS一样
再加上a[i] > a[j],这不就OK了。
代码如下:
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
#include <string>
#include <cctype>
#include <set> using namespace std;
const int maxn = 1000 + 10;
int a[maxn], d[maxn]; int main(){
int n;
while(scanf("%d", &n) && n){ a[0] = 0; int m = -1;
for(int i = 0; i < n; ++i){ scanf("%d", &a[i+1]); m = max(m, a[i+1]); } memset(d, 0, sizeof(d));
for(int i = 1; i <= n; ++i){
d[i] = a[i];
for(int j = 1; j < i; ++j){
if(a[i] > a[j]){
if(d[j] + a[i] > d[i]){
d[i] = a[i] + d[j];
m = max(m, d[i]);
}
}
}
} printf("%d\n",m);
}
return 0;
}
HDU 1087 Super Jumping! Jumping! Jumping! (DP+LIS)的更多相关文章
- HDU 4669 Mutiples on a circle (DP , 统计)
转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents by---cxlove 题意:给出一个环,每个点是一个数字,取一个子串,使 ...
- HDU 5078 Revenge of LIS II(dp LIS)
Problem Description In computer science, the longest increasing subsequence problem is to find a sub ...
- codeforces 340D Bubble Sort Graph(dp,LIS)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Bubble Sort Graph Iahub recently has lea ...
- HDU 5773:The All-purpose Zero(贪心+LIS)
http://acm.hdu.edu.cn/showproblem.php?pid=5773 The All-purpose Zero Problem Description ?? gets an ...
- hdu----(1257)最少拦截系统(dp/LIS)
最少拦截系统 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- POJ 2533 Longest Ordered Subsequence(dp LIS)
Language: Default Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 65536K Total Submis ...
- HDU - 6197:array array array (简单LIS)
One day, Kaitou Kiddo had stolen a priceless diamond ring. But detective Conan blocked Kiddo's path ...
- HDU 1087 Super Jumping! Jumping! Jumping
HDU 1087 题目大意:给定一个序列,只能走比当前位置大的位置,不可回头,求能得到的和的最大值.(其实就是求最大上升(可不连续)子序列和) 解题思路:可以定义状态dp[i]表示以a[i]为结尾的上 ...
- 取数字(dp优化)
取数字(dp优化) 给定n个整数\(a_i\),你需要从中选取若干个数,使得它们的和是m的倍数.问有多少种方案.有多个询问,每次询问一个的m对应的答案. \(1\le n\le 200000,1\le ...
随机推荐
- SAP PP中关于工单报工的小解
一般来说工单确认的方法很多,这里就简要介绍下几种常见的报工方法: 1.co11n 是大家常用的方法之一,也是比较好用,产量,报废,返工,工时,货物移动都可以输入.介于我们公司的业务我们用这个报工是最多 ...
- egret -纹理集的制作
1. 理集的使用 :http://www.codeandweb.com/ 下载软件: TexturePackergithub: 相关工具:https://github.com/ping-chen/eg ...
- caffe openpose/Realtime Multi-Person 2D Pose Estimation using Part Affinity Fields配置(转)
Realtime Multi-Person 2D Pose Estimation using Part Affinity Fields 是CVPR2017的一篇论文,作者称是世界上第一个基于深度学习的 ...
- MySQLReport
简介: MySQLReport 一.安装 shell > yum -y install mysqlreport perl-DBD-MySQL 二.使用 shell > mysqlrepor ...
- devel包
devel 包主要是供开发用,至少包括以下2个东西:1. 头文件2. 链接库有的还含有开发文档或演示代码. 以 glib 和 glib-devel 为例: 如果你安装基于 glib 开发的程序,只需要 ...
- 吴裕雄 数据挖掘与分析案例实战(10)——KNN模型的应用
# 导入第三方包import pandas as pd # 导入数据Knowledge = pd.read_excel(r'F:\\python_Data_analysis_and_mining\\1 ...
- 在hadoop运行tensor flow
http://www.infoq.com/cn/articles/deeplearning-tensorflow-casestudy http://www.tuicool.com/articles/a ...
- Windows平台下Flutter安装,配置,初运行。
Flutter是什么?他是谷歌根据Dark语言开源的跨平台开发依赖.和目前比较火的Reactive Native一样,一套代码能够实现两个不同平台的App.那么为什么要介绍Flutter而不是在国内大 ...
- Ajax 与 jquery
jquery 里面的ajax用法: $.ajax({ 参数设置: 如果返回数据不是json的时候,记得转化为json . var data = json.parse(data); json 可以直接点 ...
- Python iter() 函数
Python iter() 函数 Python 内置函数 描述 iter() 函数用来生成迭代器. 语法 以下是 iter() 方法的语法: iter(object[, sentinel]) 参数 ...