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. Factorial Trailing Zeroes Add to List

    https://leetcode.com/problems/factorial-trailing-zeroes/#/description 想到了要找2x5:也想到了只要找5,剩下的2 管够.也想到了 ...

  2. 【原创】java socket 和.net socket 通讯 demo

    结束符协议"##" import java.io.BufferedReader; import java.io.IOException; import java.io.InputS ...

  3. jmeter访问mysql数据库

    jdbc:mysql://localhost:3306/jy?allowMultiQueries=true 如果想同时执行多条语句

  4. VM VirtualBox – Cannot register the hard disk

    第一打开VirtualBox 文件夹,在地址栏输入cmd 第二, 仔细读下面 VBoxManage.exe  internalcommands  sethduuid  "F:\Virtual ...

  5. HDU1814 Peaceful Commission 2-sat

    原文链接http://www.cnblogs.com/zhouzhendong/p/8099115.html 题目传送门 - HDU1814 题面 Description 根据宪法,Byteland民 ...

  6. Spring日记_02之搭建一个新项目

    程序 表现层 业务层 持久层 从持久层开始写 总结如何搭建一个项目 1.新建一个Maven项目 2.可能新建之后会有错,右键Deployment Descriptor: note, 选择Generat ...

  7. NSL:CPK_NN神经网络实现预测哪个样本与哪个样本处在同一层,从而科学规避我国煤矿突水灾难—Jason niu

    load water_data.mat attributes = mapminmax(attributes); P_train = attributes(:,1:35); T_train = clas ...

  8. Linux学习之查看系统资源命令总结(二十二)

    Linux系统之查看系统资源总结 . 转载:http://lxbins.blog.51cto.com/1089997/283663 top命令:监控系统 top 主要参数 d:指定更新的间隔,以秒计算 ...

  9. python数据结构之插入排序

    插入排序(英语:Insertion Sort)是一种简单直观的排序算法.它的工作原理是通过构建有序序列,对于未排序数据,在已排序序列中从后向前扫描,找到相应位置并插入.插入排序在实现上,在从后向前扫描 ...

  10. 在Qt项目中添加全局宏变量来达到按方案编译的目的

    遇到一个需求,需要根据不同需要编译所需程序,本人采用了在QtCreator中建立不同的构建设置,配合宏的方式来实现: 1.在项目-构建设置中,添加构建配置2.在构建步骤里的qmake中的额外参数一栏填 ...