https://vjudge.net/problem/HDU-1003

注意考虑如果全为负的情况,特判。

还有输出格式,最后一个输出不用再空行。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define IO ios::sync_with_stdio(false);cin.tie(0);
#define INF 1e9
typedef long long ll;
using namespace std;
int n, m, a[];
int main()
{
IO;
cin >> n;
int kase=;
while(n--){
cin >> m;
for(int i = ; i < m; i++){
cin >> a[i];
}
int sum = , maxm = -INF;
int from = ;
int ans1 = , ans2 = -;
for(int i = ; i < m; i++){
sum += a[i];
if(sum < ){
sum = ;
from = i+;
}
else{
if(sum > maxm){
maxm = sum;
ans1 = from;
ans2 = i;
}
}
}
cout << "Case " << ++kase << ":" << endl;
if(ans2 == -){//sum一直小于零,每位<0
maxm = -INF;
for(int i = ; i < m; i++){
if(a[i] > maxm){
maxm = a[i];
ans1 = i; ans2 = i;
}
}
cout << maxm << " " << ans1+ << " " << ans2+ << endl;
}
else
cout << maxm << " " << ans1+ << " " << ans2+ << endl;
if(n != ) cout << endl;
}
return ;
}

hdu1003 Max Sum(最大子串)的更多相关文章

  1. 解题报告:hdu1003 Max Sum - 最大连续区间和 - 计算开头和结尾

    2017-09-06 21:32:22 writer:pprp 可以作为一个模板 /* @theme: hdu1003 Max Sum @writer:pprp @end:21:26 @declare ...

  2. [ACM_动态规划] hdu1003 Max Sum [最大连续子串和]

    Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum ...

  3. 杭电60题--part 1 HDU1003 Max Sum(DP 动态规划)

    最近想学DP,锻炼思维,记录一下自己踩到的坑,来写一波详细的结题报告,持续更新. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003 Problem ...

  4. HDU1003 Max Sum(求最大字段和)

    事实上这连续发表的三篇是一模一样的思路,我就厚颜无耻的再发一篇吧! 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003 -------------- ...

  5. hdu1003 Max Sum(经典dp )

      A - 最大子段和 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Descr ...

  6. HDU--1003 Max Sum(最大连续子序列和)

    Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum ...

  7. HDU-1003 Max Sum(动态规划,最长字段和问题)

    Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  8. ACM学习历程—HDU1003 Max Sum(dp && 最大子序列和)

    Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub ...

  9. hdu1003 Max Sum【最大连续子序列之和】

    题目链接:https://vjudge.net/problem/HDU-1003 题目大意:给出一段序列,求出最大连续子序列之和,以及给出这段子序列的起点和终点. 解题思路:最长连续子序列之和问题其实 ...

随机推荐

  1. net core体系-API-1Ocelot-(2)继续深入

    简单的说Ocelot是一个用.NET Core实现并且开源的API网关技术.可能你又要问了,什么是API网关技术呢?Ocelot又有什么特别呢?我们又该如何集成到我们的asp.net core程序中呢 ...

  2. Spring AOP中args()、arg-names、argNames

    先小结一下: args()是用来匹配并且接收目标方法的参数的. argNames(用在注解中)与arg-names(用在XML中),他们是同一个东西. argNames用来接收AspectJ表达式中的 ...

  3. BZOJ2178 圆的面积并 计算几何 辛普森积分

    原文链接https://www.cnblogs.com/zhouzhendong/p/BZOJ2178.html 题目传送门 - BZOJ2178 题意 给出 $n(n\leq 1000)$ 个圆,求 ...

  4. 2018牛客网暑假ACM多校训练赛(第四场)A Ternary String 数论

    原文链接https://www.cnblogs.com/zhouzhendong/p/NowCoder-2018-Summer-Round4-A.html 题目传送门 - https://www.no ...

  5. BZOJ1010 [HNOI2008]玩具装箱toy 动态规划 斜率优化

    原文链接http://www.cnblogs.com/zhouzhendong/p/8687797.html 题目传送门 - BZOJ1010 题意 一个数列$C$,然后把这个数列划分成若干段. 对于 ...

  6. netty02(接受消息以后进行返回)

    到这里接着上一篇netty01开始,没看过的可以点进去看一下再来 首先来说一下 ByteBuf   这个类吧,这个类是netty里面提供的,接受信息和返回信息格式都是它: ByteBuf   是一个抽 ...

  7. 058 kafka与log4j集成

    1.首先在resources下面写log4j.properties 主要是因为kafka.producer.KafkaLog4jAppender类的存在. log4j.rootLogger=INFO, ...

  8. vee-validate校验demo

    //太长了,把异步校验放到前面吧: VeeValidate.Validator.extend('checkLoginName',{ getMessage:function () { return &q ...

  9. Python3.4+Django1.9+Bootstrap3

    实现和原理 Python集成Django开发框架后,可以通过在cmd命令提示符下建立工程,工程名为learn_models 1 django-admin.py startproject learn_m ...

  10. 【LeetCode算法-14】Longest Common Prefix

    Write a function to find the longest common prefix string amongst an array of strings. If there is n ...