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. postman-变量

    Variables 什么是变量 变量是一个符号,可以接受不同的值.你可能根据你的项目经验,对其他语言的变量比较熟悉.在postman 的工作原理也是一样的 为什么使用变量 变量允许你在不同的地方重复使 ...

  2. Shell中的特殊字符(三)

    一 通配符 [root@192 test]# touch abc [root@192 test]# touch abcd [root@192 test]# touch 012 [root@192 te ...

  3. OverFeat:基于卷积网络的集成识别、定位与检测

    摘要:我们提出了一个使用卷积网络进行分类.定位和检测的集成框架.我们展示了如何在ConvNet中有效地实现多尺度和滑动窗口方法.我们还介绍了一种新的深度学习方法,通过学习预测对象边界来定位.然后通过边 ...

  4. 我的Android案例签到日历

    2015年的Android案例之旅 案例八:签到日历 知识点: GridView的使用SQLite的使用 涉及文件: res->layout->activity_main.xml 主布局文 ...

  5. Window、Linux查看本机外网ip

    前言 我们上网用的IP并不一定是本机网卡的IP地址,由于公网IP地址稀少,国内绝大多数电脑上网,一般都是通过拨号或者端口映射.多个内网地址映射到一个公网地址来实现上网的. 目录 1.查看本机网卡ip ...

  6. C++学习一二

    为了更深入的学习程序编写,以及进行相关算法的编写.决定每天花点时间学习C++:以下是每天的学习笔记. 一.std代表命名空间,可以用using来省略. 二.std:endl.输出一个换行符,并且“刷新 ...

  7. docker 容器不能联网

    Unknown Endpoint: Inaccessible host: `dynamodb.us-east-1.amazonaws.com' 别慌!Docker容器内不能联网的6种解决方案 注:下面 ...

  8. 使用jdk自带的visualVM监控远程监控was

    1.登录was控制台https://172.16.87.221:9043/ibm/console/unsecureLogon.jsp服务器--服务器类型--Java 和进程管理---进程定义---Ja ...

  9. 洛谷P4095新背包问题

    传送 这道题最最暴力的方法就是对于每一个询问都跑一边多重背包问题,但显然q不会那么友好的让我们用暴力过掉这道题. 考虑优化.我们可以先把裸的多重背包搞成二进制优化后的多重背包.但是复杂度依然无法接受. ...

  10. @Aspect 注解切面解析

    注解切面解析 注解切面解析器 /** * 注解切面解析器 */ public class BeanFactoryAspectJAdvisorsBuilder { /** * Bean 工厂 */ pr ...