Max Sum

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 132258    Accepted Submission(s): 30652

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
 
Author
Ignatius.L
 

最大连续和sum....运用动态规划思想

 #include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
int n,j,i,num,a,ans,maxc,posst,posen,temp;
scanf("%d",&n);
for(i=;i<=n;i++)
{
scanf("%d",&num);
maxc=;
posst=posen=;
ans=-0x3f3f3f3f ;
temp=;
for(j=;j<=num;j++)
{
scanf("%d",&a);
maxc+=a;
if(ans<maxc)
{
ans=maxc;
posen=j;
posst=temp+;
}
if(maxc<)
{
maxc=;
temp=j;
}
}
printf("Case %d:\n%d %d %d\n",i,ans,posst,posen);
if(i!=n) putchar();
}
return ;
}

HDUOJ--------1003 Max Sum的更多相关文章

  1. HDU 1003 Max Sum --- 经典DP

    HDU 1003    相关链接   HDU 1231题解 题目大意:给定序列个数n及n个数,求该序列的最大连续子序列的和,要求输出最大连续子序列的和以及子序列的首位位置 解题思路:经典DP,可以定义 ...

  2. HDOJ(HDU).1003 Max Sum (DP)

    HDOJ(HDU).1003 Max Sum (DP) 点我挑战题目 算法学习-–动态规划初探 题意分析 给出一段数字序列,求出最大连续子段和.典型的动态规划问题. 用数组a表示存储的数字序列,sum ...

  3. hdu 1003 Max Sum (DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003 Max Sum Time Limit: 2000/1000 MS (Java/Others)   ...

  4. hdu 1003 MAX SUM 简单的dp,测试样例之间输出空行

    测试样例之间输出空行,if(t>0) cout<<endl; 这样出最后一组测试样例之外,其它么每组测试样例之后都会输出一个空行. dp[i]表示以a[i]结尾的最大值,则:dp[i ...

  5. HDU 1003 Max Sum【动态规划求最大子序列和详解 】

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

  6. #1003 Max Sum

    http://acm.hdu.edu.cn/showproblem.php?pid=1003 给你一串数列,让你求出其中 一段连续的子数列 并且 该子数列所有数字之和最大,输出该子数列的和.起点与终点 ...

  7. 杭电1003 Max Sum 【连续子序列求最大和】

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1003 题目意思: 即给出一串数据,求连续的子序列的最大和 解题思路: 因为我们很容易想到用一个max ...

  8. hdu 1003 Max sum(简单DP)

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

  9. HDU 1003 Max Sum

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

  10. HDU 1003 Max Sum 解题报告

    题目大意:求一串数字中,几个连续数字加起来最大值,并确定起始和最末的位置. 思路:这是一题DP题,但是可以用尺取法来做.我一开始不会,也是看了某大神的代码,然后有人告诉我这是尺取法,现在会了. //尺 ...

随机推荐

  1. Android之在Tab更新两个ListView,让一个listview有按下另个一个listview没有的效果

    直接上代码,不说了 UpdateListViewItem.zip

  2. UCN(User-Centric Networks,用户中心网络)

    UCN(User-Centric Networks,以用户为中心的网络)是下一代移动通信网络(5G)的发展方向,目前尚处于初级发展阶段.2016年11月,IEEE SDN研究组(聚焦研发SDN.NFV ...

  3. iOS:NSDate的主要几种时间形式

    NSDate:时间的获取和操作 1.获取当前时间 //获取当前日期 NSDate *date = sender.date; NSLog(@"%@",date); 2.将date转换 ...

  4. SystemVerilog Event Scheduling Algorithm

    While simulating System Verilog design and its test-bench including assertions, events has to be dyn ...

  5. data-stream-as-disjoint-intervals

    https://leetcode.com/problems/data-stream-as-disjoint-intervals/ /** * Definition for an interval. * ...

  6. 依赖注入 DI 控制反转 IOC MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  7. jquery圆角插件

    为了实现div的圆角效果,你还在用古老的背景图片拼凑的方法吗?还是在用各种浏览器不互相兼容的CSS方式?如果你还在用这样的方式实现圆角,那我告诉你你真的out了,或许是我out了,竟然以前没发现有这样 ...

  8. js实现trim() JS去掉首尾空格 JS去掉两头空格

    function trimStr(str){ return str.replace(/(^\s*)|(\s*$)/g,""); } 用的时候就是直接 var 变量=trimStr( ...

  9. Golang 中使用多维 map

    http://tnt.wicast.tk/2015/11/02/golang-multiple-dimension-map/ Golang 的 XML/JSON 解析库乍看使用起来很方便,只要构造一样 ...

  10. 超全Linux备份工具集合,满足你的所有需要!

    经常备份计算机上的数据是个好的做法,它可以手动完成,也可以设置成自动执行.许多备份工具拥有不同的功能特性,让用户可以配置备份类型.备份时间.备份对象.将备份活动记入日志及执行更多操作. 1.Rsync ...