Max Partial Value I

Time Limit: 1000/5000 MS (Java/Others)    Memory Limit: 32768/65535 K (Java/Others)

Problem Description
HenryFour has a number of stones which have different values from -4444 to 4444. He puts N stones in a line and wants to find the max partial value of these N stones.



Assume the values of the N stones in line are: v1, v2, v3, v4, ..., vN. The partial vaule of stones from Lth stone to Rth stone (1 ≤ L ≤ R ≤ N) is the sum of all the stones between them. i.e. PartialV(L, R) = v[L] + v[L+1] + .... + v[R] (1 ≤ L ≤ R ≤ N) 



Since the number of stones (N) is very very large, it is quite difficult for HenryFour to find the max partial value. So could you develop a programme to find out the answer for him? 
 
Input
There are several test cases in the input data. The first line contains a positive integer T (1 ≤ T ≤ 14), specifying the number ot test cases. Then there are T lines. Each of these T lines contains a positive number N followed by N integers which indicate
the values of the N stones in line.

1 ≤ N ≤ 1,000,000

-4444 ≤ v[i] ≤ 4444 
 
Output
Your program is to write to standard output. For each test case, print one line with three numbers seperated by one blank: P L R. P is the max partial value of the N stones in line. L and R indicate the position of the partial stones. If there are several Ls
and Rs that have the same value PartialV(Li, Ri) = P, please output the minimum pair. For pair (Li, Ri) and (Lj, Rj), we define (Li, Ri) < (Lj, Rj) if and only if: Li < Lj or (Li == Lj and Ri < Rj) 
 
Sample Input
3
4 32 -39 -30 -28
8 1 2 3 -10 1 -1 5 1
10 14 -12 -8 -13 3 5 42 -24 -32 -12
 
Sample Output
32 1 1
6 1 3
50 5 7

记得以前做过一样的题,而且还水过了,但在这里WA了一整天,整个人都不好了,如果要求最大和的话分分钟水过,但又要求把下标求出,,,”
If there are several Ls and Rs that have the same value PartialV(Li, Ri) = P, please output the minimum pair. For pair (Li, Ri) and (Lj, Rj), we define (Li, Ri) < (Lj, Rj) if and only if: Li < Lj or (Li == Lj and
Ri < Rj) “,千万要注意这点,是要在最大和相同的前提下把最靠近左边的输出,如 0 1,输出应该是 1 1 2;而不是1 2 2;

解决了这个问题还要注意用long long ,不过目测不会超int啊,奇怪;

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
using namespace std;
const int N=1000000+10;
int a[N];
int main()
{
int t,n,i,j,k;
long long maxsum,x;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
x=0;
maxsum=-10000000;
j=k=1;
int j1=1,k1=1;
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
if(x>=0)
{
x+=a[i];
k1=i;
}
else
{
x=a[i];
j1=k1=i;
}
if(x>maxsum)
{
maxsum=x;
j=j1;
k=k1;//核心也就这么一点,连动规都不算;
}
}
printf("%I64d %d %d\n",maxsum,j,k);
}
return 0;
}

HDU-1858-Max Partial Value I,有坑点,不难;的更多相关文章

  1. HDU 1858 Max Partial Value I

    求连续子序列的最大和 为毛简单的入门DP没有思路啊.. 学习下别人的解法,理解起来倒还是很容易的. //#define LOCAL #include <iostream> #include ...

  2. HDU 1024 Max Sum Plus Plus --- dp+滚动数组

    HDU 1024 题目大意:给定m和n以及n个数,求n个数的m个连续子系列的最大值,要求子序列不想交. 解题思路:<1>动态规划,定义状态dp[i][j]表示序列前j个数的i段子序列的值, ...

  3. HDU 1003 Max Sum --- 经典DP

    HDU 1003    相关链接   HDU 1231题解 题目大意:给定序列个数n及n个数,求该序列的最大连续子序列的和,要求输出最大连续子序列的和以及子序列的首位位置 解题思路:经典DP,可以定义 ...

  4. HDU 1244 Max Sum Plus Plus Plus

    虽然这道题看起来和 HDU 1024  Max Sum Plus Plus 看起来很像,可是感觉这道题比1024要简单一些 前面WA了几次,因为我开始把dp[22][maxn]写成dp[maxn][2 ...

  5. hdu 3415 Max Sum of Max-K-sub-sequence(单调队列)

    题目链接:hdu 3415 Max Sum of Max-K-sub-sequence 题意: 给你一串形成环的数,让你找一段长度不大于k的子段使得和最大. 题解: 我们先把头和尾拼起来,令前i个数的 ...

  6. hdu 2993 MAX Average Problem(斜率DP入门题)

    题目链接:hdu 2993 MAX Average Problem 题意: 给一个长度为 n 的序列,找出长度 >= k 的平均值最大的连续子序列. 题解: 这题是论文的原题,请参照2004集训 ...

  7. HDU 1024 Max Sum Plus Plus (动态规划)

    HDU 1024 Max Sum Plus Plus (动态规划) Description Now I think you have got an AC in Ignatius.L's "M ...

  8. HDOJ(HDU).1003 Max Sum (DP)

    HDOJ(HDU).1003 Max Sum (DP) 点我挑战题目 算法学习-–动态规划初探 题意分析 给出一段数字序列,求出最大连续子段和.典型的动态规划问题. 用数组a表示存储的数字序列,sum ...

  9. HDU 1024 max sum plus

    A - Max Sum Plus Plus Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I6 ...

随机推荐

  1. eclipse快捷键,移动和复制一段代码

    移动代码:alt+上或下箭头 复制加移动代码:ctrl + alt + 上或下箭头

  2. 146 LRU Cache 最近最少使用页面置换算法

    设计和实现一个  LRU(最近最少使用)缓存 数据结构,使它应该支持以下操作: get 和 put .get(key) - 如果密钥存在于缓存中,则获取密钥的值(总是正数),否则返回 -1.put(k ...

  3. Git之提交项目到远程github

    1.在分支dev下,默认本地工作区有项目project 2. git add project  [添加项目到暂存区] 3. git commit project -m "提交项目" ...

  4. hihocoder offer收割编程练习赛9 B 水陆距离

    思路: 宽搜,多个起点. 实现: #include <iostream> #include <cstdio> #include <algorithm> #inclu ...

  5. 为Qt添加SSL支持

    目标:为Qt添加SSL支持,使得应用可以发送HTTPS请求 环境:win7,Qt4.8.6 步骤: 1.到http://slproweb.com/products/Win32OpenSSL.html下 ...

  6. PMP项目管理学习笔记(11)——范围管理之定义范围

    定义范围过程组 定义范围包含将项目分解为团队成员要完成的具体工作之前你需要知道的所有一切. 输入:需求文档.项目章程.组织过程资产 工具:辅助工作室.产品分析.代理方案识别.专家判断 辅助工作室: 与 ...

  7. C# 调用第三方DLL缓冲区溢出导致的异常

    这个倒是少见的错误,纪录一下大佬. 先上异常 错误一:尝试读取或写入受保护的内存 错误二:未将对象引用设置到对象的实例 错误三:  托管调试助手“FatalExecutionEngineError”( ...

  8. raid 0 1 5 10 总结的知识点

    raid 0 1 5 10 raid 发的别名条带 raid 0 读取性能最高需要磁盘2*N个(N>0)代表所有raid级别中的最高存储性能,其实原理就是把连续的数据分散到多个磁盘上存取,这样, ...

  9. c++ cpp和hpp

    首先,我们可以将所有东西都放在一个.cpp文件内,编译器会将这个.cpp编译成.obj,即编译单元.一个程序可以由一个编译单元组成,也可以由多个编译单元组成.一个.cpp对应一个.obj,然后将所有的 ...

  10. vue计算属性computed和methods的区别

    computed和methods的区别 在new Vue的配置参数中的computed和methods都可以处理大量的逻辑代码,但是什么时候用哪个属性,要好好区分一下才能做到正确的运用vue. com ...