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. [js高手之路] es6系列教程 - 迭代器与生成器详解

    什么是迭代器? 迭代器是一种特殊对象,这种对象具有以下特点: 1,所有对象都有一个next方法 2,每次调用next方法,都会返回一个对象,该对象包含两个属性,一个是value, 表示下一个将要返回的 ...

  2. node.js的generic-pool与mysql结合,mysql连接池

    var generic_pool = require('generic-pool'); var pool = generic_pool.Pool({     name: 'mysql',     ma ...

  3. XCode消除警告、错误

    1.集成支付宝SDK后,报一堆warning: (arm64) /Users/scmbuild/workspace/standard-pay/.....警告 解决方法: 1)  Go to Build ...

  4. vue2.0 网页标题更新实现思路

    一.注册全局指令 1.注册一个全局指令 Vue.directive('title', { inserted: function (el, binding) { document.title = el. ...

  5. [js高手之路] html5 canvas动画教程 - 实时获取鼠标的当前坐标

    有了前面的canvas基础之后,现在开始就精彩了,后面写的canvas教程都是属于综合应用,前面已经写了常用的canvas基础知识,参考链接如下: [js高手之路] html5 canvas系列教程 ...

  6. 经典算法研究系列:二、Dijkstra 算法初探

    July   二零一一年一月 本文主要参考:算法导论 第二版.维基百科. 一.Dijkstra 算法的介绍 Dijkstra 算法,又叫迪科斯彻算法(Dijkstra),算法解决的是有向图中单个源点到 ...

  7. 用MXNet实现mnist的生成对抗网络(GAN)

    用MXNet实现mnist的生成对抗网络(GAN) 生成式对抗网络(Generative Adversarial Network,简称GAN)由一个生成网络与一个判别网络组成.生成网络从潜在空间(la ...

  8. 学习如何看懂SQL Server执行计划(二)——函数计算篇

    二.函数计算部分 --------------------标量聚合--------------------/* 标量聚合-主要在聚合函数操作中产生 计算标量:根据行中的现有值计算出一个新值 流聚合:在 ...

  9. flex的三个属性:

    (1)flex-grow:指的是相对于其他的子元素的扩展比率:默认值为0:数字 (2)flex-basis:指的是子元素的具体长度:可以为长度(rem,px,em)也可以为百分比: (3)flex-s ...

  10. hadoop streaming编程小demo(python版)

    大数据团队搞数据质量评测.自动化质检和监控平台是用django,MR也是通过python实现的.(后来发现有orc压缩问题,python不知道怎么解决,正在改成java版本) 这里展示一个python ...