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 ...
随机推荐
- Others-Goldengate 数据同步
GoldenGate 是一家创建于1995年的美国公司,开发总部设在旧金山,在北美,欧洲和亚洲(包括新加坡.印度.澳大利亚)设有支持中心. 公司名称 GoldenGate 总部地点 旧金山 成立时间 ...
- vue基础——表单输入绑定
一.基础用法 你可以用 v-model 指令在表单 <input> 及 <textarea> 元素上创建双向数据绑定.它会根据控件类型自动选择正确的方法来更新元素. 尽管有些神 ...
- AJAX是什么?
AJAX的全称是Asynchronous JavaScript and XML(异步的 JavaScript 和 XML). ajax不是新的编程语言,而是一种使用现有标准的新方法.ajax是与服务器 ...
- Haskell语言学习笔记(33)Exception, Except, ExceptT
Exception class (Typeable e, Show e) => Exception e where toException :: e -> SomeException fr ...
- ng2-file-upload 使用记录
最近这两周一直在修bug,修的很是痛苦,不过痛苦也是件好事,不然每天都是在做同样的事情,没有什么挑战,工作多无聊呀! 是吧. 大致说一下背景吧: 这个项目是两年前开新项目,到现在一直还在开发中,一直不 ...
- session会话时间
session对象失效在下列情况下被删除: A.程序调用HttpSession.invalidate() B.距离上一次收到客户端发送的session id时间间隔超过了session的最大有效时间 ...
- 显示AVI的第一桢
procedure TForm1.Button1Click(Sender: TObject);begin Application.ProcessMessages; MediaPlayer1.Ope ...
- @Transactionl注解
spring 事务注解 默认遇到throw new RuntimeException("...");会回滚 需要捕获的throw new Exception("...&q ...
- python 解析 yaml文件
import yaml with open("./test.yaml") as f: x = yaml.load(f) print(x) [{'tasks': [{'yum': { ...
- Ansible test
[root@localmesos ansible_test]# ansible all -a "/bin/echo hello"192.168.111.111 | SUCCESS ...