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. E470 外放没声音问题解决

    到官网下载声卡驱动.和热键驱动,安装就ok了

  2. unity 3D游戏场景转换

    //////////////////2015/07/07//////// /////////////////by xbw/////////////// ///////////////环境 unity ...

  3. Java – Top 5 Exception Handling Coding Practices to Avoid

    This article represents top 5 coding practices related with Java exception handling that you may wan ...

  4. 线性判别分析(Linear Discriminant Analysis, LDA)算法分析

    原文来自:http://blog.csdn.net/xiazhaoqiang/article/details/6585537 LDA算法入门 一. LDA算法概述:       线性判别式分析(Lin ...

  5. Informatica 常用组件Source Qualifier之八 Distinct

    如果希望 PowerCenter 从源选择唯一值,您可以使用"选择相异"选项.例如,您可以使用此功能从列出总销售额的表中提取唯一客户标识.使用"选择相异"过滤器 ...

  6. HDU 3910 (13.10.31)

    Description Maybe you know “San Guo Sha”, but I guess you didn’t hear the game: “Liang Guo Sha”! Let ...

  7. 【反射】Reflect Class Field Method Constructor

    关于反射 Reflection 面试题,什么是反射(反射的概念)? 主要是指程序可以访问,检测和修改它本身状态或行为的一种能力,并能根据自身行为的状态和结果,调整或修改应用所描述行为的状态和相关的语义 ...

  8. Spark性能优化:数据倾斜调优

    前言 继<Spark性能优化:开发调优篇>和<Spark性能优化:资源调优篇>讲解了每个Spark开发人员都必须熟知的开发调优与资源调优之后,本文作为<Spark性能优化 ...

  9. 揭开Faiss的面纱 探究Facebook相似性搜索工具的原理

    https://www.leiphone.com/news/201703/84gDbSOgJcxiC3DW.html 本月初雷锋网报道,Facebook 开源了 AI 相似性搜索工具 Faiss.而在 ...

  10. Android控件之HorizontalScrollView 去掉滚动栏

    在默认情况下.HorizontalScrollView控件里面的内容在滚动的情况下,会出现滚动栏,为了去掉滚动栏.仅仅须要在<HorizontalScrollView/>里面加一句    ...