博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Max Sum 贪心
阅读量:5812 次
发布时间:2019-06-18

本文共 1414 字,大约阅读时间需要 4 分钟。

                                                                                                                    Max Sum

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
using namespace std;int a[100000];void maxSubSum(int a[], int n){ int maxSum=-1001, thisSum=-1001, start=0, end=0, p=0; for(int i=0; i
maxSum){ maxSum = thisSum; start = p; end = i; } } cout<
<<" "<
<<" "<
<
>t; for(i=1; i<=t; i++){ int n; cin>>n; for(int j=0; j
>a[j]; if(i!=1) cout<

转载于:https://www.cnblogs.com/Genesis2018/p/8304814.html

你可能感兴趣的文章
没有JS的前端:体积更小、速度更快!
查看>>
数据指标/表现度量系统(Performance Measurement System)综述
查看>>
GitHub宣布推出Electron 1.0和Devtron,并将提供无限制的私有代码库
查看>>
Angular2, NativeScript 和 React Native比较[翻译]
查看>>
论模式在领域驱动设计中的重要性
查看>>
国内首例:飞步无人卡车携手中国邮政、德邦投入日常运营
查看>>
微软将停止对 IE 8、9和10的支持
查看>>
微服务架构会和分布式单体架构高度重合吗
查看>>
如何测试ASP.NET Core Web API
查看>>
《The Age of Surge》作者访谈
查看>>
测试人员的GitHub
查看>>
Spring Web Services 3.0.4.RELEASE和2.4.3.RELEASE发布
查看>>
有关GitHub仓库分支的几个问题
查看>>
无服务器计算的黑暗面:程序移植没那么容易
查看>>
云原生的浪潮下,为什么运维人员适合学习Go语言?
查看>>
Webpack入门教程三十
查看>>
EAServer 6.1 .NET Client Support
查看>>
锐捷交换机密码恢复(1)
查看>>
Kali linux virtualbox rc=1908 错误解决办法
查看>>
linux软件包管理之三(源代码安装)
查看>>