博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 1003 Max Sum (DP)
阅读量:6565 次
发布时间:2019-06-24

本文共 1956 字,大约阅读时间需要 6 分钟。

Max Sum

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 134690    Accepted Submission(s): 31181

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
 

 

Recommend
We have carefully selected several similar problems for you:            
 
简单dp思想:
1 //15 MS    236 KB    Visual C++     2 #include
3 int main(void) 4 { 5 int t,n,k=1; 6 int a; 7 scanf("%d",&t); 8 while(t--) 9 {10 if(k>1) printf("\n");11 scanf("%d",&n);12 int l=1,r=1,sum=-0x7ffffff,tmp=0,tl=1;13 for(int i=1;i<=n;i++){14 scanf("%d",&a);15 tmp+=a;16 if(tmp>sum){17 sum=tmp;18 l=tl;19 r=i;20 }21 if(tmp<0){22 tmp=0;23 tl=i+1; 24 }25 }26 printf("Case %d:\n",k++);27 printf("%d %d %d\n",sum,l,r);28 }29 return 0;30 }31 /*32 33 3034 3 -1 0 -135 3 -1 0 136 3 -1 -2 -337 38 */

 

转载于:https://www.cnblogs.com/GO-NO-1/p/3683969.html

你可能感兴趣的文章
linux安装至少有哪两个分区,各自作用是什么?
查看>>
转载: 数据库索引原理和优缺点
查看>>
swoole 安装和简单实用
查看>>
文件系统 第八次迭代 VFS相关说明
查看>>
InfoPi运行机制介绍
查看>>
速读《构建之法:现代软件工程》提问
查看>>
SpringCloud注册中心环境搭建euraka
查看>>
各类文件的文件头标志
查看>>
第四周作业——在你的实际项目旅游网站中,网页主页面主要有哪些模块?
查看>>
基于django的个人博客网站建立(一)
查看>>
ElasticSearch 安装使用
查看>>
使用nodejs创建加入用户验证的websocket服务
查看>>
反思最近这些时日的荒废
查看>>
React性能分析利器来了,妈妈再也不用担心我的React应用慢了(转)
查看>>
cocos2dx新建android项目lib拷贝、访问权限等问题集
查看>>
软工学习记3
查看>>
信息安全管理(1):组织的三个层面
查看>>
Eclipse导入Hadoop源码项目及编写Hadoop程序
查看>>
HDU4462(子集枚举)
查看>>
原生JS实现圆周运动
查看>>