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>
using namespace std;
int main()
{
int T,c=;
scanf("%d",&T);
while(T--)
{
int N,i,sum=,max=-,t=,start,end,n;
cin>>N;
for(i=;i<=N;i++)
{
scanf("%d",&n);
sum=sum+n;
if(sum>max)
{
max=sum;
start=t;
end=i;
}
if(sum<)
{
sum=;t=i+;
}
}
cout<<"Case "<<c++<<":"<<endl;
cout<<max<<" "<<start<<" "<<end<<endl;
if(T!=)
cout<<endl;
}
32}

Max Sum(最大子序和)的更多相关文章

  1. Leetcode#53.Maximum Subarray(最大子序和)

    题目描述 给定一个序列(至少含有 1 个数),从该序列中寻找一个连续的子序列,使得子序列的和最大. 例如,给定序列 [-2,1,-3,4,-1,2,1,-5,4], 连续子序列 [4,-1,2,1] ...

  2. Leetcode——53.最大子序和

    @author: ZZQ @software: PyCharm @file: leetcode53_最大子序和.py @time: 2018/11/26 12:39 要求:给定一个整数数组 nums ...

  3. tyvj1305 最大子序和 【单调队列优化dp】

    描述 输入一个长度为n的整数序列,从中找出一段不超过M的连续子序列,使得整个序列的和最大. 例如 1,-3,5,1,-2,3 当m=4时,S=5+1-2+3=7 当m=2或m=3时,S=5+1=6 输 ...

  4. leetcode-最大子序和(动态规划讲解)

    最大子序和(动态规划讲解) 给定一个整数数组 nums ,找到一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和. 示例: 输入: [-2,1,-3,4,-1,2,1,-5,4], 输 ...

  5. Leecode刷题之旅-C语言/python-53.最大子序和

    /* * @lc app=leetcode.cn id=53 lang=c * * [53] 最大子序和 * * https://leetcode-cn.com/problems/maximum-su ...

  6. tyvj1305 最大子序和(单调队列

    题目地址:http://www.joyoi.cn/problem/tyvj-1305 最大子序和 题目限制 时间限制 内存限制 评测方式 题目来源 1000ms 131072KiB 标准比较器 Loc ...

  7. Tyvj1305最大子序和(单调队列优化dp)

    描述 输入一个长度为n的整数序列,从中找出一段不超过M的连续子序列,使得整个序列的和最大. 例如 1,-3,5,1,-2,3 当m=4时,S=5+1-2+3=7当m=2或m=3时,S=5+1=6 输入 ...

  8. 【LeetCode】53.最大子序和

    最大子序和 给定一个整数数组 nums ,找到一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和. 示例: 输入: [-2,1,-3,4,-1,2,1,-5,4], 输出: 6 解释: ...

  9. LeetCode 53. 最大子序和(Maximum Subarray)

    53. 最大子序和 53. Maximum Subarray 题目描述 给定一个整数数组 nums,找到一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和. LeetCode53. M ...

随机推荐

  1. 阅读&lt;反欺骗的艺术&gt;思考

    早期接受csdn发送本书<反欺骗的艺术 ---- 传说中的黑客世界里,分享经验>. 经过这本书发生床头, 每天晚上看上.直到今天, 刚读的书. 颇有感觉. 之所以当初选择读这本书, 完全被 ...

  2. RH033读书笔记(5)-Lab 6 Exploring the Bash Shell

    Lab 6 Exploring the Bash Shell Sequence 1: Directory and file organization 1. Log in as user student ...

  3. 2.大约QT数据库操作,简单的数据库连接操作,增删改查数据库,QSqlTableModel和QTableView,事务性操作,大约QItemDelegate 代理

     Linux下的qt安装,命令时:sudoapt-get install qt-sdk 安装mysql数据库,安装方法參考博客:http://blog.csdn.net/tototuzuoquan ...

  4. OWIN 为WebAPI

    OWIN 为WebAPI 宿主 跨平台 OWIN是什么? OWIN的英文全称是Open Web Interface for .NET. 如果仅从名称上解析,可以得出这样的信息:OWIN是针对.NET平 ...

  5. ZOJ Problem Set - 2563 Long Dominoes 【如压力dp】

    称号:ZOJ Problem Set - 2563 Long Dominoes 题意:给出1*3的小矩形.求覆盖m*n的矩阵的最多的不同的方法数? 分析:有一道题目是1 * 2的.比較火.链接:这里 ...

  6. 从头开始建网站(三)DNS

    前面介绍了站点搭建所须要的两大要素:域名和server,这次要说的是域名解析,也就是把域名和server进行绑定的过程. 我们在訪问网络时,网址会被发送到DNSserver,然后由DNSserver返 ...

  7. Chrome console(转)

    阅读目录 写在前面 谷歌控制台Elements面板 查看元素上绑定的事情 样式操作 总况 console.log console.info console.error console.warn con ...

  8. 改变,从跨出第一步開始——记海大ITAEM团队首次IT讲座掠影

    之前以前写了"行动带来力量,周三(5月7日)晚IT讲座通知",昨晚已经跨出了第一步.让我们还是看举办者骆宏的QQ空间的文字吧.尽管未能到现场助兴,但看着海大学子在不断挑战自己,进而 ...

  9. C++指针和引用简介

    摘要 本文介绍C++指针和概念引用 这是一个指针 指针的类型 指针所指向的类型 指针表达式 指针与函数 什么是引用 指针引用差别 指针和引用的同样点和不同点 **什么是指针** 指针就是一个存放地址的 ...

  10. sqlserver 无法初始化via支持库[QLVIPL.DLL]

    安装数据库后,在sqlserver configuration manager, sqlserver的网络配置,有将协议 shared memory,named pipes,tcp/ip,via全部启 ...