| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 919 人关注过本帖
标题:acm题目1003,求解
只看楼主 加入收藏
czj201610032
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2016-11-4
结帖率:0
收藏
已结贴  问题点数:20 回复次数:3 
acm题目1003,求解
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.

2016-11-04 21:41
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:10 
有个毛毛虫,一开始在左边,头部往右爬,如果毛毛虫占据的数之和小于等于0,则将将尾部缩到头部。
以上就是遍历过程,记录每一次的和的最大值
2016-11-05 14:56
yangfrancis
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:贵宾
威 望:141
帖 子:1510
专家分:7661
注 册:2014-5-19
收藏
得分:10 
回复 2楼 rjsp
不行的。如果数列是-1,-2,-3...最后得到的最大值不会是-1
2016-11-05 16:48
yangfrancis
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:贵宾
威 望:141
帖 子:1510
专家分:7661
注 册:2014-5-19
收藏
得分:0 
回复 2楼 rjsp
刚才没想清楚。可以得到正确值。因为阶段性的最大值有记录的
2016-11-05 16:51
快速回复:acm题目1003,求解
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.044014 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved