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. 

InputThe 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). 
OutputFor 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<cstring>
#include<cstdio> using namespace std; void Solve(){
int n, x, st, h = , t = , tmp, ans = ;
static int Case = ;
scanf("%d", &n);
for(int i = ; i <= n; i++){
scanf("%d", &x);
if(i == ){
st = t = ;
tmp = ans = x;
}else{
if(x > tmp + x){
st = i;
tmp = x;
}else tmp += x;
}
if(tmp > ans){
h = st, t = i;
ans = tmp;
}
}
printf("Case %d:\n%d %d %d\n", ++Case, ans, h, t);
}
int main(){
int T;
scanf("%d", &T);
while(T--){
Solve();
if(T) printf("\n");
}
}

最大连续和 Easy的更多相关文章

  1. leetcode485——最大连续1的个数(easy)

    一.题目描述 给定一个二进制数组, 计算其中最大连续1的个数. 示例 1: 输入: [1,1,0,1,1,1] 输出: 3 解释: 开头的两位和最后的三位都是连续1,所以最大连续1的个数是 3. 注意 ...

  2. ZOJ3802 Easy 2048 Again (状压DP)

    ZOJ Monthly, August 2014 E题 ZOJ月赛 2014年8月 E题 http://acm.zju.edu.cn/onlinejudge/showProblem.do?proble ...

  3. 【BZOJ3450】Tyvj1952 Easy 期望DP

    [BZOJ3450]Tyvj1952 Easy Description 某一天WJMZBMR在打osu~~~但是他太弱逼了,有些地方完全靠运气:(我们来简化一下这个游戏的规则有n次点击要做,成功了就是 ...

  4. 【tyvj1952】easy

    AK大神又AK了!!! orzorzorz 题意: 给出一个字符串由'x'.'o'.'?' '?'有一半的几率为'x' 一半几率为'o' 得分为所有连续的'o'的个数的平方和 如ooxooo 得分为2 ...

  5. Bzoj 3450: Tyvj1952 Easy 期望/概率,动态规划

    3450: Tyvj1952 Easy Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 431  Solved: 325[Submit][Status] ...

  6. tyvj P1952 Easy(递推+期望)

    P1952 Easy 时间: 1000ms / 空间: 131072KiB / Java类名: Main 描述 某一天WJMZBMR在打osu~~~但是他太弱逼了,有些地方完全靠运气:(我们来简化一下 ...

  7. ACM-DP最大连续子——hdu1231

    ***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...

  8. 3450: Tyvj1952 Easy

    3450: Tyvj1952 Easy Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 269  Solved: 198[Submit][Status] ...

  9. [Tyvj 1952] Easy

    P1952 Easy 时间: 1000ms / 空间: 131072KiB / Java类名: Main 描述 某一天WJMZBMR在打osu~~~但是他太弱逼了,有些地方完全靠运气:(我们来简化一下 ...

随机推荐

  1. The Preliminary Contest for ICPC Asia Shanghai 2019 J. Stone game

    题目:https://nanti.jisuanke.com/t/41420 思路:当a(a∈S′)为最小值 如果Sum(S′)−a≤Sum(S−S′)成立 那么(∀t∈S′,Sum(S′)−t≤Sum ...

  2. CDOJ 1059 秋实大哥与小朋友 STL(set)+离散化+BIT区间更新单点查询

    链接: A - 秋实大哥与小朋友 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%lld & %llu Subm ...

  3. Linux下cs简单通讯(socket)

    Server: #include<iostream> #include<sys/types.h> #include<sys/socket.h> #include&l ...

  4. The GuidRepresentation for the reader is CSharpLegacy, which requires the binary sub type to be Uuid

    使用客户端链接MongoDb报错 The GuidRepresentation for the reader is CSharpLegacy, which requires the binary su ...

  5. Linux安装vsftpd及配置详解

    1 安装vsftpd组件 安装完后,有/etc/vsftpd/vsftpd.conf 文件,是vsftp的配置文件.[root@bogon ~]# yum -y install vsftpd 2.FT ...

  6. 大哥带的Orchel数据库时间盲注

    0X01Oracle基于延时的盲注总结 0x00 前言 oracle注入中可以通过页面响应的状态,这里指的是响应时间,通过这种方式判断SQL是否被执行的方式,便是时间盲注: oracle的时间盲注通常 ...

  7. python正则之match search findall

    match:只匹配一次,开头匹配不上,则不继续匹配 a,b,\w+ match(a,"abcdef") 匹配a >>> re.match("a" ...

  8. C语言第四次实验报告

    第四次实验报告 一·实验项目名称: 多球反弹 二·实验项目功能描述: (1)实现多个小球 (2)实现多个小球碰壁会反弹 (3)实现小球之间碰撞反弹 三· 项目模块结构介绍 #define High 4 ...

  9. memcached空指针内存错误与死循环问题分析(memcached dead loop and crash bug! issue #260 and issue #370)

    (由于这是发在memcached邮件列表的,所以只能用一下蹩脚的英文了) (you should read the discuss about issue #260 first:  https://g ...

  10. nginx利用try_files实现多个源

    比如一个视频网站,视频资源分散在几台机器上,但是给用要提供统一的IP,路径,端口.就需要nginx,先检查本机是否有改文件,如果没有就代理其他地方 location / { root /data/ww ...