Problem 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

题目:给你一个序列,求最大连续序列的和;

解题思路:这个题上学期就写过了,Max
Sum,上学期最后期末复习,不爱学高数了,就把杭电的题挨着写,第一页写了一半;但是没用DP,用一个maxn记录当前序列最大的和,从头枚举连续数列,最后输出maxn;

感悟:总结隔着一天才写的,因为时间太长了,早忘了当初写的什么;

代码:

#include

int main()

{   int
t,i,max=-1001,start=0,end=0,temp=0,sum=0;

int a;

long n;

scanf("%d",&t);

for(int i=1;i<=t;i++)

{  
if(i!=1)

printf("\n");

scanf("%d",&n);

max=-1001,start=0,end=0,temp=1,sum=0;

for(int j=1;j<=n;j++)

{  
scanf("%d",&a);

sum+=a;

if(sum>max)

{  
max=sum;

end=j;

start=temp;

}

if(sum<0)


sum=0;

temp=j+1;

}

}

printf("Case %d:\n",i);

printf("%d %d %d\n",max,start,end);

}

return 0;

}

Problem A的更多相关文章

  1. 1199 Problem B: 大小关系

    求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...

  2. No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.

    Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...

  3. C - NP-Hard Problem(二分图判定-染色法)

    C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:262144 ...

  4. Time Consume Problem

    I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...

  5. Programming Contest Problem Types

        Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...

  6. hdu1032 Train Problem II (卡特兰数)

    题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能.    (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...

  7. BZOJ2301: [HAOI2011]Problem b[莫比乌斯反演 容斥原理]【学习笔记】

    2301: [HAOI2011]Problem b Time Limit: 50 Sec  Memory Limit: 256 MBSubmit: 4032  Solved: 1817[Submit] ...

  8. [LeetCode] Water and Jug Problem 水罐问题

    You are given two jugs with capacities x and y litres. There is an infinite amount of water supply a ...

  9. [LeetCode] The Skyline Problem 天际线问题

    A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...

  10. PHP curl报错“Problem (2) in the Chunked-Encoded data”解决方案

    $s = curl_init(); curl_setopt($s, CURLOPT_POST, true); curl_setopt($s, CURLOPT_POSTFIELDS, $queryStr ...

随机推荐

  1. 比较JqGrid与XtraGrid

    此只能比较两者的功能优劣,实现某种功能.效果的方便性和效率.首先分别粗略介绍XtraGrid和jqGrid DevExpress是目前.net下最为强大和完整的UI控件库, XtraGrid是这个控件 ...

  2. Apache服务器处理404错误页面技巧

    1.打开Apache目录,查找httpd.conf文件 2.打开httpd.conf文件,找到<Directory "    "></Directory>这 ...

  3. iOS Storyboard约束详解

    链接:http://www.jianshu.com/p/b88c65ffc3eb 约束,就是指--此处略去1万字--都懂的,就不说了.直接进入实战环节. 本文的控件约束都是围绕着UITableView ...

  4. 【JVM命令系列】javap

    命令基本概述 javap是JDK自带的反汇编器,可以查看java编译器为我们生成的字节码.通过它,可以对照源代码和字节码,从而了解很多编译器内部的工作.可以在命令行窗口先用javap -help看下j ...

  5. 关于SSH

    SSH的英文全称是Secure Shell. 传统的网络服务程序,如:ftp和telnet在本质上都是不安全安全安全安全的,因为它们在网络上用明文传送口令和数据,别有用心的人非常容易就可以截获这些口令 ...

  6. MySQL之多表操作

    前言:之前已经针对数据库的单表查询进行了详细的介绍:MySQL之增删改查,然而实际开发中业务逻辑较为复杂,需要对多张表进行操作,现在对多表操作进行介绍. 前提:为方便后面的操作,我们首先创建一个数据库 ...

  7. 上传文件没有写权限Access to the path is denied

    Access to the path is denied. asp.net程序目录放在系统盘,ntfs格式. 程序中对cfg.xml有写入操作. 运行的时候出现了这个问题. 在我自己的机器上没有问题 ...

  8. Python实战之用类的静态方法实现登录验证

    #!usr/bin/env Python3 # -*-coding:utf-8-*- __author__="William" #define a class,just to le ...

  9. python下selenium测试报告整合

    使用过一段时间的Robot Framework测试框架,测试之前需要先搭环境,需要安装的东西很多,这一点个人有些排斥. 每一个测试内容对应一个Test_Case,Robot有自己语法格式,如判断.循环 ...

  10. 将 C# 枚举反序列化为 JSON 字符串 基础理论

    该转换过程需要引用 Newtonsoft.JSON,这其中的转换过程还是蛮有意思的. 一.定义枚举 /// <summary> /// 托寄物品枚举 /// </summary> ...