事实上这连续发表的三篇是一模一样的思路,我就厚颜无耻的再发一篇吧!

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003

----------------------------------------------------------------------------------------------------------------------------------------------------------
欢迎光临天资小屋http://user.qzone.qq.com/593830943/main

----------------------------------------------------------------------------------------------------------------------------------------------------------

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

代码例如以下:

#include <cstdio>
#define INF 0x3fffffff
#define M 100000+17
int a[M];
int main()
{
int n, i, T, k = 0;
while(~scanf("%d",&T))
{
while(T--)
{
scanf("%d",&n);
int s = 1, e = 1, t = 1;
int sum = 0, MAX = -INF;
for(i = 1; i <= n; i++)
{
scanf("%d",&a[i]);
sum+=a[i];
if(sum > MAX)
{
s = t;
e = i;
MAX = sum;
}
if(sum < 0)
{
t = i+1;
sum = 0;
}
}
printf("Case %d:\n",++k);
printf("%d %d %d\n",MAX,s,e);
if(T!=0)
printf("\n");
}
}
return 0;
}

HDU1003 Max Sum(求最大字段和)的更多相关文章

  1. 解题报告:hdu1003 Max Sum - 最大连续区间和 - 计算开头和结尾

    2017-09-06 21:32:22 writer:pprp 可以作为一个模板 /* @theme: hdu1003 Max Sum @writer:pprp @end:21:26 @declare ...

  2. HDU-1003 Max Sum(动态规划,最长字段和问题)

    Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  3. hdu1003 Max Sum(经典dp )

      A - 最大子段和 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Descr ...

  4. ACM学习历程—HDU1003 Max Sum(dp && 最大子序列和)

    Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub ...

  5. HDU--1003 Max Sum(最大连续子序列和)

    Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum ...

  6. HDU 1003 Max Sum 求区间最大值 (尺取法)

    Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Su ...

  7. [ACM_动态规划] hdu1003 Max Sum [最大连续子串和]

    Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum ...

  8. 杭电60题--part 1 HDU1003 Max Sum(DP 动态规划)

    最近想学DP,锻炼思维,记录一下自己踩到的坑,来写一波详细的结题报告,持续更新. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003 Problem ...

  9. hdu1003 Max Sum【最大连续子序列之和】

    题目链接:https://vjudge.net/problem/HDU-1003 题目大意:给出一段序列,求出最大连续子序列之和,以及给出这段子序列的起点和终点. 解题思路:最长连续子序列之和问题其实 ...

随机推荐

  1. mssql 容易掉进的坑

    1.     重复 使用 into #tabel(不是在开头使用insert into ) 会报错   if  1=1 begin  select * into #tabel from product ...

  2. 配置spring管理的bean的作用域

    .singleton 在每一个spring Ioc容器中一个bean定义只有一个对象实例.默认情况下会在容器启动时初始化bean,但我们可以指定bean节点的lazy-init = "tru ...

  3. MFC CString的L和_T

    这个问题困扰了很久,这个解释貌似好理解一些 L表示UNICODE串,比如wchar_t* str = L"yangsongx";_T在ANSI编译模式下表示ANSI串,在UNICO ...

  4. 服务器安装Linux应该注意的问题

    安装方式: 1.光盘安装 2.睿捷引导安装 3.u盘安装 4.硬盘安装 5.IPMI远程安装 其中,睿捷是最方便的方式,驱动直接都会安装好,但是睿捷支持的Linux系统只有两个,局限性比较大: 光盘和 ...

  5. 一些推荐的spark/hadoop课程

    为了分享给你们,也为自己. 感谢下面的老师们! 1.王家林DT大数据梦工厂的大数据IMF传奇行动课程 总的目录是: 第一阶段:Linux和Java零基础企业级实战 第二阶段:Hadoop和Hive零基 ...

  6. c++面试题总结(1)

    1.int a=5,则 ++(a++)的值是() A.5      B.   6          C.7       D.逻辑错误 a++返回的是一个临时变量,这里是右值,不能再前面++了 2.下面 ...

  7. linux 分区与挂载

    流程:分区-格式化-挂载 1.添加硬盘 使用fdisk -l命令查看磁盘状态 此处可以看到两块硬盘sda和sdb,第一块硬盘sda是装好系统的.sdb硬盘是未进行分区的. 本例将这个20G的硬盘分区, ...

  8. MSSQL手札二 MSSQL的触发器

    触发器,就是在对表做DML操作的时候,触发一些其他的事件,触发器一般用在check约束更加复杂的约束上面,是一种特殊的存储过程,不可以被主动调用. 语法如下: CREATE TRIGGER trigg ...

  9. c++字符串机理

    在windows编程中,由于编码方式的不同和c与c++的不同而造成了许多复杂的有关字符串之间的转换 首先,windows编码方式有ANSCLL和UNICODE,前者是单字符的,后者是双字符的. 然后, ...

  10. IC各元器件封装形式图解

    CDIP-----Ceramic Dual In-Line Package CLCC-----Ceramic Leaded Chip Carrier CQFP-----Ceramic Quad Fla ...