hdu1087 最大递增子段和
http://acm.split.hdu.edu.cn/showproblem.php?pid=1087
状态方程:sum[j]=max{sum[i]}+a[j]; 其中,0<=i<=j,a[i]<a[j]
把当前最大和更新到数组中,注意顺序。
Input
Input contains multiple test cases. Each test case is described in a line as follow:
N value_1 value_2 …value_N
It is guarantied that N is not more than 1000 and all value_i are in the range of 32-int.
A test case starting with 0 terminates the input and this test case is not to be processed.
Output
For each case, print the maximum according to rules, and one line one case.
Sample Input
3 1 3 2
4 1 2 3 4
4 3 3 2 1
0
Sample Output
4
10
3
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define INF 0xfffffff int a[];
int dp[]; int main()
{
int n;
while(scanf("%d",&n)== && n)
{
for(int i=; i<=n; i++)
scanf("%d",&a[i]);
memset(dp,,sizeof(dp));
int ans;
for(int i=; i<=n; i++)
{
ans=-INF;
for(int j=; j<i; j++)
if(a[i]>a[j])
ans=max(ans,dp[j]);
dp[i]=ans+a[i];
}
ans=-INF;
for(int i=; i<=n; i++)
ans=max(ans,dp[i]);
printf("%d\n",ans);
}
return ;
}
hdu1087 最大递增子段和的更多相关文章
- HDU1087 Super Jumping! Jumping! Jumping! 最大连续递增子段
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- dp-最大递增子段和
Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. M ...
- HDU1087:Super Jumping! Jumping! Jumping!(DP)
Problem Description Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very ...
- Super Jumping! Jumping! Jumping!——E
E. Super Jumping! Jumping! Jumping! Time Limit: 1000ms Memory Limit: 32768KB 64-bit integer IO forma ...
- 转载:hdu 动态规划题集
1.Robberies 连接 :http://acm.hdu.edu.cn/showproblem.php?pid=2955 背包;第一次做的时候把概率当做背包(放大100000倍化为整数): ...
- dp 46(再做一遍)
Robberies http://acm.hdu.edu.cn/showproblem.php?pid=2955 背包;第一次做的时候把概率当做背包(放大100000倍化为整数):在此范围内最多能抢多 ...
- hdu 动态规划(46道题目)倾情奉献~ 【只提供思路与状态转移方程】(转)
HDU 动态规划(46道题目)倾情奉献~ [只提供思路与状态转移方程] Robberies http://acm.hdu.edu.cn/showproblem.php?pid=2955 背包 ...
- 杭电dp题集,附链接还有解题报告!!!!!
Robberies 点击打开链接 背包;第一次做的时候把概率当做背包(放大100000倍化为整数):在此范围内最多能抢多少钱 最脑残的是把总的概率以为是抢N家银行的概率之和- 把状态转移方程写成了f ...
- 【转载】 HDU 动态规划46题【只提供思路与状态转移方程】
1.Robberies 连接 :http://acm.hdu.edu.cn/showproblem.php?pid=2955 背包;第一次做的时候把概率当做背包(放大100000倍化为整数) ...
随机推荐
- <context-param>与<init-param>
<context-param>的作用: web.xml的配置中<context-param>配置作用1. 启动一个WEB项目的时候,容器(如:Tomcat)会去读它的配置文件w ...
- [Android Pro] Android 4.1 使用 Accessibility实现免Root自动批量安装功能
reference to : http://www.infoq.com/cn/articles/android-accessibility-installing?utm_campaign=info ...
- webApp路由控制-vue-router2.0
安装 直接下载 / CDN https://unpkg.com/vue-router 中文api: http://router.vuejs.org/zh-cn/index.html
- webstorm配置scss自动编译路径
webstorm支持sass的同步编译,也就是即写即编译,并且可以指定编译后的css的目录. 本文使用的webstorm为8.0版本 scss安装:http://www.w3cplus.com/sas ...
- 解决springmvc 前台取不到值
查看web.xml 如果为web-app_2_3.xsd spring不支持 修改项目为web-app_2_4.xsd
- linux下U盘文件只读的解决办法
. 在终端运行如下命令 tail -f /var/log/syslog . 插入有只读文件系统故障的U盘 . 观察命令行输出 输出局部如下: Jul :: cslouis-pc kernel: [15 ...
- java web统计当前访问用户数量
1.使用SessionListener监听器,监听创建与销毁session的操作,利用计数方式记录当前session的数量
- Http返回码
HTTP协议状态码表示的意思主要分为五类 ,大体是 : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1×× 保留 2×× 表示请求成功地接收 3×× 为完成请求客户需 ...
- python异步爬虫
本文主要包括以下内容 线程池实现并发爬虫 回调方法实现异步爬虫 协程技术的介绍 一个基于协程的异步编程模型 协程实现异步爬虫 线程池.回调.协程 我们希望通过并发执行来加快爬虫抓取页面的速度.一般的实 ...
- 两个viewport的故事(第二部分)
原文:http://www.quirksmode.org/mobile/viewports2.html 在这个迷你系列的文章里边我将会解释viewport,以及许多重要元素的宽度是如何工作的,比如&l ...