题意:给定一个长度为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)的更多相关文章

  1. HDU 4669 Mutiples on a circle (DP , 统计)

    转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove 题意:给出一个环,每个点是一个数字,取一个子串,使 ...

  2. HDU 5078 Revenge of LIS II(dp LIS)

    Problem Description In computer science, the longest increasing subsequence problem is to find a sub ...

  3. codeforces 340D Bubble Sort Graph(dp,LIS)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud  Bubble Sort Graph Iahub recently has lea ...

  4. HDU 5773:The All-purpose Zero(贪心+LIS)

    http://acm.hdu.edu.cn/showproblem.php?pid=5773 The All-purpose Zero Problem Description   ?? gets an ...

  5. hdu----(1257)最少拦截系统(dp/LIS)

    最少拦截系统 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  6. POJ 2533 Longest Ordered Subsequence(dp LIS)

    Language: Default Longest Ordered Subsequence Time Limit: 2000MS   Memory Limit: 65536K Total Submis ...

  7. HDU - 6197:array array array (简单LIS)

    One day, Kaitou Kiddo had stolen a priceless diamond ring. But detective Conan blocked Kiddo's path ...

  8. HDU 1087 Super Jumping! Jumping! Jumping

    HDU 1087 题目大意:给定一个序列,只能走比当前位置大的位置,不可回头,求能得到的和的最大值.(其实就是求最大上升(可不连续)子序列和) 解题思路:可以定义状态dp[i]表示以a[i]为结尾的上 ...

  9. 取数字(dp优化)

    取数字(dp优化) 给定n个整数\(a_i\),你需要从中选取若干个数,使得它们的和是m的倍数.问有多少种方案.有多个询问,每次询问一个的m对应的答案. \(1\le n\le 200000,1\le ...

随机推荐

  1. Utils使用

    获取两个时间之间的天数 var startDate = new Date(_startDate).getTime(); var endDate = new Date(_endDate).getTime ...

  2. 前端-javascript-ECMAScript5.0

    -前端常用开发工具:sublime.visual Studio Code.HBuilder.Webstorm. 使用的PCharm跟WebStorm是JetBrains公司推出的编辑工具,开发阶段建议 ...

  3. SVD 实现

    机器学习相关——SVD分解: http://www.cnblogs.com/luchen927/archive/2012/01/19/2321934.html SVD python实现: import ...

  4. git hg提交拉取

    工作总结web_acl 535 git clone “ssh://git@outergit.yonyou.com:49622/esn_web/web_acl.git" 600 git bra ...

  5. 大型运输行业实战_day02_2_数据模型建立

    1.模型分析 1.基本必备字段 id   state  type   createTime   updateTime 2.车票  :   车次   开始车站   到达车站   出发时间    票价   ...

  6. Java8 Stream语法详解 2

    1. Stream初体验 我们先来看看Java里面是怎么定义Stream的: A sequence of elements supporting sequential and parallel agg ...

  7. django MongoDB上传文件

    django上传文件,查询到的资料都是用的django自己的models.Model类,去定义一个FileField类型的存储文件,并且在里面加一句upload_to,如下所示:   但是如果用mon ...

  8. Dubbo简单理解

    Dubbo 致力于提供高性能和透明化的RPC远程服务调用方案,以及SOA服务治理方案.简单的说,Dubbo就是个服务框架,如果没有分布式的需求,其实是不需要用的,只有在分布式的时候,才有Dubbo这样 ...

  9. 70. Climbing Stairs (Array; DP)

    You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...

  10. 通过阿里OSS文件服务返回的URL获取文件流下载

    我们都知道将文件上传到阿里的OSS文件服务上后,可以通过generatePresignedUrl(bucketName, key, expiration)方法获取该文件的防问路径,但是当我们知道该文件 ...