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

本文共 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

你可能感兴趣的文章
Asf PHP扩展框架之预警模块介绍
查看>>
无处安放的AndroidTips:ConstraintLayout的比例布局
查看>>
在 React-CRA 应用中配合 VSCode 使用 ESLint 实践前端代码规范
查看>>
[NodeJs系列]NodeJs模块机制
查看>>
从前端角度理解缓存
查看>>
rook使用教程,快速编排ceph
查看>>
「读懂源码系列1」还在恐惧读源码?看完这篇就不怕了
查看>>
【zzzmh个人博客】一枚Java程序的个人建站之路 (干货)
查看>>
进入docker的世界
查看>>
轻量级内存计算引擎
查看>>
边缘计算 VS 云计算,谁才是未来
查看>>
Laravel5.4 升级到 5.6
查看>>
从javascript到python(一):基本环境搭建
查看>>
[LeetCode] 797. All Paths From Source to Target
查看>>
Jenkins 用户文档(使用Maven构建Java应用程序)
查看>>
ReactNative入门教程-项目结构解析及HelloWorld
查看>>
ECMAScript 2015(ES6)有用的提示与技巧
查看>>
JavaScript是如何工作的:Web Workers的构建块+ 5个使用他们的场景
查看>>
leetcode讲解--589. N-ary Tree Preorder Traversal
查看>>
NodeJS 服务器数据处理(表单、json 字符串和普通字符串)
查看>>