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. PT2264解码心得

    PT2264解码心得 最近闲暇时间在琢磨无线RF解码程序,正好在数码之家论坛中翻出大佬的解码程序(http://bbs.mydigit.cn/read.php?tid=245739),于是乎,慢慢学习 ...

  2. redis本地安装与开发

    一.安装(MAC) https://redis.io sudo mv redis-4.0.11.tar.gz /usr/localcd /usr/localsudo tar -zxf redis-4. ...

  3. 解决vue跨域问题

    package com.qmtt.config; import java.io.IOException; import javax.servlet.Filter; import javax.servl ...

  4. 8.bootstrap下拉菜单、按钮组、按钮式下拉菜单

    下拉菜单 dropdown 对齐方式: .dropdown-menu-right     .dropdown-menu-left <div class="container" ...

  5. 微信小程序 逻辑层

    1. 注册程序小程序APP在小程序的根目录下有一个app.js文件.有App(Object),App() 函数用来注册一个小程序.接受一个 Object 参数,其内便是小程序的生命周期.App() 必 ...

  6. ArcGIS二次开发之读取遥感图像像素值的做法

    作者:朱金灿 来源:http://blog.csdn.net/clever101 首先是读取遥感图像的R.G.B波段数据的做法.读取R.G.B波段数据的像素值主要通过IRaster接口的Read方法在 ...

  7. tar.bz2

    tar -xvjf gcc-4.1.0.tar.bz2 bzip2 -d  gcc-4.1.0.tar.bz2

  8. 时间插件-daterangepicker

    一款基于bootstrap的时间插件daterangepicker,顾名思义,主要用于时间区间选择,也可做单个时间选择 demo.1汉化版的一个时间选择案例 <!DOCTYPE html> ...

  9. 原生js的容易忽略的相似点(二)

    1.new Object 和字面量 {}测试; <script type="text/javascript"> //1.new出来对象 console.log(obj, ...

  10. C++ isalpha、isalnum、islower、isupper用法

    1. isalpha isalpha()用来判断一个字符是否为字母,如果是字符则返回非零,否则返回零. cout<<isalpha('a'); //返回非零 cout<<isa ...