Description

Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 + 4 = 14.

Input

The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line starts with a number N(1<=N<=100000), then N integers followed(all the integers are between -1000 and 1000).

Output

For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line contains three integers, the Max Sum in the sequence, the start position of the sub-sequence, the end position of the sub-sequence. If there are more than one result, output the first one. Output a blank line between two cases.

Sample Input

2
5 6 -1 5 4 -7
7 0 6 -1 1 -6 7 -5

Sample Output

Case 1:
14 1 4 Case 2:
7 1 6 题目大意:给出一组数,求出最大的子序列 代码如下:
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int main()
{
int i,cs,testnum;
int n,number,sum,start,end,temp,max;
scanf("%d",&testnum);
for(cs=1;cs<=testnum;cs++)
{
max=-1010;
sum=0;
temp=1;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d",&number);
sum+=number;
if(sum>max)
{
max=sum;
start=temp;
end=i;
}
if(sum<0)
{
sum=0;
temp=i+1;
}
}
printf("Case %d:\n%d %d %d\n",cs,max,start,end);
if(cs!=testnum)
printf("\n");
}
return 0;
}

  

Max Sum的更多相关文章

  1. [LeetCode] Max Sum of Rectangle No Larger Than K 最大矩阵和不超过K

    Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix s ...

  2. 2016huasacm暑假集训训练五 J - Max Sum

    题目链接:http://acm.hust.edu.cn/vjudge/contest/126708#problem/J 题意:求一段子的连续最大和,只要每个数都大于0 那么就会一直增加,所以只要和0 ...

  3. HDU 1024 max sum plus

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

  4. hdu 1024 Max Sum Plus Plus

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

  5. hdu 1003 MAX SUM 简单的dp,测试样例之间输出空行

    测试样例之间输出空行,if(t>0) cout<<endl; 这样出最后一组测试样例之外,其它么每组测试样例之后都会输出一个空行. dp[i]表示以a[i]结尾的最大值,则:dp[i ...

  6. Max Sum Plus Plus——A

    A. Max Sum Plus Plus Now I think you have got an AC in Ignatius.L's "Max Sum" problem. To ...

  7. hdu 1003 Max sum(简单DP)

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

  8. HDU 1003 Max Sum

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

  9. Leetcode: Max Sum of Rectangle No Larger Than K

    Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix s ...

随机推荐

  1. Nuget版本冲突的问题

    有两个类库项目,一个引用了比如Newtonsoft.Json 6.0, 另一个引用了比如Newtonsoft.Json 8.0, 然后另一个exe项目同时引用了这两个类库项目. 那么在编译的时候会报w ...

  2. Spring基本框架

    1.Spring基本框架的概念 Spring 框架是一个分层架构,由 7 个定义良好的模块组成.Spring模块构建在核心容器之上,核心容器定义创建.配置和管理bean的方式.组成Spring框架的每 ...

  3. Socket为什么要翻译成套接字

    作者:陈振玥链接:https://www.zhihu.com/question/21383903/answer/64103663来源:知乎著作权归作者所有,转载请联系作者获得授权. 作为一条刻(wu) ...

  4. 转:python中对list去重的多种方法

    对一个list中的新闻id进行去重,去重之后要保证顺序不变. 直观方法 最简单的思路就是: ids = [1,2,3,3,4,2,3,4,5,6,1] news_ids = [] for id in ...

  5. NodeJS 常用模块

    NodeJS 模块: n:NodeJS 版本管理/切换 参考: https://github.com/tj/n ExpressJS:Web 框架 参考: http://expressjs.com/ m ...

  6. kendo ui 富文本编辑控件 Editor 实现本地上传图片,并显示

    富文本编辑的组件有很多,大名鼎鼎的KENDO UI中自然也有,但是默认功能中,只能包含网络图片, 而如果要实现本地上传图片,KENDO UI也提供了相应的功能,但必须实现KENDO规定的多个接口, 而 ...

  7. 通用Hibernate DAO类(包括分页)

    package com.jronline.dao; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.S ...

  8. Chrome浏览器Network面板http请求时间分析

    Chrome浏览器开发者工具Network窗口下,可以查看下载各组件所需的具体时间 根据上表进行简要分析-- Stalled(阻塞) 浏览器对同一个主机域名的并发连接数有限制,因此如果当前的连接数已经 ...

  9. 循序渐进Python3(十)-- 0 -- RabbitMQ

    RabbitMQ     RabbitMQ是一个由erlang开发的AMQP(Advanced Message Queue )的开源实现.AMQP 的出现其实也是应了广大人民群众的需求,虽然在同步消息 ...

  10. java生成带logo的二维码,自定义大小,logo路径取服务器端

    package com.qishunet.eaehweb.util; import java.awt.BasicStroke; import java.awt.Graphics; import jav ...