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倍化为整数) ...
随机推荐
- python2.x和3.x的区别
这个星期开始学习Python了,因为看的书都是基于 Python2.x,而且我安装的是Python3.1,所以书上写的地方好多都不适用于Python3.1,特意在Google上search了一下 3. ...
- java转换json需要导入的jar包,org/apache/commons/lang/exception/NestableRuntimeException
缺少相应jar包都会有异常,根据异常找jar包导入...... 这里我说下lang包,因为这个包我找了好半天: 我用的是: commons-lang3-3.1.jar 出现异常: jav ...
- Javascript调用C#后台方法及JSon解析
Javascript调用C#后台方法及JSon解析 如何使用Ajax 调用C# 后台方法. 本文目录 如何使用Ajax 调用C# 后台方法. 1.后台(.cs)测试方法 2.前台调用(javasc ...
- JavaBean中set/get的命名规范
今天遇到了这样的问题,在jsp取session中的值时,取不到.有个SessionUser对象,该对象有个uId属性,set/get方法为setUId/getUId,在jsp页面通过el表达式取值${ ...
- lazyload
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- Java IO流题库
一. 填空题 Java IO流可以分为 节点流 和处理流两大类,其中前者处于IO操作的第一线,所有操作必须通过他们进行. 输入流的唯一目的是提供通往数据的通道,程序可以通过这个通道读取数 ...
- osg::NodeVisitor中计算一个节点对应的世界变换矩阵、法向量、顶点坐标
class MyNodeVisitor:public osg::NodeVisitor { pulic: MyNodeVisitor():osg::NodeVisitor(osg::NodeVisit ...
- 解决spring+shiro cacheManager 登录报错
一.项目启动,登录报错 org.springframework.beans.factory.BeanCreationException: Error creating bean with name ' ...
- 使用vsphere client 克隆虚拟机
免费的VMWare ESXi5.0非常强大,于是在vSphere5.0平台中ESXi取代了ESX.,使用ESXi经常会遇到这样的问题,我需要建立多个虚拟机,都是windows2003操作系统,难道必须 ...
- 消息队列MQ - Apache ActiveMQ
Apache ActiveMQ是Apache软件基金会所研发的开放源码消息中间件:由于ActiveMQ是一个纯Jave程式,因此只需要操作系统支持Java虚拟机,ActiveMQ便可执行. 1.que ...