Max Sum

Time Limit: 1000ms
Memory Limit: 32768KB
 
This problem will be judged on HDU. Original ID: 1003
64-bit integer IO format: %I64d      Java class name: Main
 
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 解题:dp入门题!弱菜的成长之路啊!
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#define LL long long
using namespace std;
int dp[],num[];
int main(){
int kase,i,index,ans,n,k = ;
scanf("%d",&kase);
while(kase--){
scanf("%d",&n);
for(i = ; i <= n; i++)
scanf("%d",dp+i);
num[] = ;
ans = dp[index = ];
for(i = ; i <= n; i++){
if(dp[i] <= dp[i-]+dp[i]){
dp[i] = dp[i-]+dp[i];
num[i] = num[i-]+;
}else num[i] = ;
if(ans < dp[i]) ans = dp[index = i];
}
printf("Case %d:\n",k++);
printf("%d %d %d\n",ans,index-num[index],index);
if(kase) putchar('\n');
}
return ;
}

BNUOJ 5227 Max Sum的更多相关文章

  1. [LeetCode] Max Sum of Rectangle No Larger Than K 最大矩阵和不超过K

    Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix s ...

  2. 2016huasacm暑假集训训练五 J - Max Sum

    题目链接:http://acm.hust.edu.cn/vjudge/contest/126708#problem/J 题意:求一段子的连续最大和,只要每个数都大于0 那么就会一直增加,所以只要和0 ...

  3. Max Sum

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

  4. HDU 1024 max sum plus

    A - Max Sum Plus Plus Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I6 ...

  5. hdu 1024 Max Sum Plus Plus

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

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

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

  7. Max Sum Plus Plus——A

    A. Max Sum Plus Plus Now I think you have got an AC in Ignatius.L's "Max Sum" problem. To ...

  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 ...

随机推荐

  1. 优秀Java程序员的四大忌,你避免了吗?

    做为一名优秀的程序员需要具备永不放弃的精神,如果一个程序员不具备这种永不放弃的精神,那么这个程序员只能算是一名假程序员.而通往成功的道路上往往是不平坦的,想要成为一个合格的高级Java程序员,需要规避 ...

  2. 洛谷 P1048 采药

    采药 01背包模板题. #include <iostream> #include <cstdio> using namespace std; //Mystery_Sky //一 ...

  3. Oracle数据仓库创建教程

    Oracle数据仓库创建教程.如何创建一个数据仓库,创建实例,以为毕业设计要求,最近开始Oracle的数仓建模实践,详细记录了图形界面下的 Oracle database 12C 数据仓库创建过程. ...

  4. Android WiFi使用记录

    最近在做Android的WiFi部分的开发,连接的工具类参照了这个文章的工具类. http://www.cnblogs.com/zhuqiang/p/3566686.html 开发中碰上的一些问题,在 ...

  5. Postgres远程访问配置

    在服务器上安装了Postgres数据库,然后通过客户端工具pgAdminIII来远程访问的过程中发现提醒服务器没有启动监听的错误.解决方法如下: 编辑Postgres安装路径下的/data/pg_hb ...

  6. App Transport Security has blocked a cleartext HTTP

    打开info.plist源代码复制粘贴     <key>NSAppTransportSecurity</key>     <dict> <!--Includ ...

  7. libxml2.dylb 导致<libxml/tree.h> 老是找不到头文件

    添加了libxml2.dylb的framework ,结果还是引用不了<libxml/tree.h>,  老是提示找不到头文件. 这个问题其实比较容易解决,但是XCode的版本问题确实让开 ...

  8. Robot Framework(十三) 执行测试用例——创建输出

    3.5创建输出 执行测试时会创建几个输出文件,并且所有这些文件都与测试结果有某种关联.本节讨论创建的输出,如何配置它们的创建位置以及如何微调其内容. 3.5.1不同的输出文件 输出目录 输出文件 日志 ...

  9. 插入函数概念 接收一个callback,然后外面函数,接一个对象,和一个next,外面都执行完了,继续执行下一个函数,相当于一个链状体,插入了一个函数的概念 | log4js 输出 等于 console.info

    插入函数概念 接收一个callback,然后外面函数,接一个对象,和一个next,外面都执行完了,继续执行下一个函数,相当于一个链状体,插入了一个函数的概念 app.use(function (ctx ...

  10. 前端知识点总结——HTML

    HTML:HTML4.01 指的就是网页技术HTML5:HTML4.01的升级版本 1.web的基础知识 web与Internet1.Internet:全球性的计算机互联网络,因特网,互联网,交互网2 ...