HDU 1003 Max Sum
来源:互联网 发布:c多线程编程实例 pdf 编辑:程序博客网 时间:2024/06/03 14:30
Max Sum
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 187999 Accepted Submission(s): 43803
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
25 6 -1 5 4 -77 0 6 -1 1 -6 7 -5
Sample Output
Case 1:14 1 4Case 2:7 1 6
Author
Ignatius.L
Recommend
We have carefully selected several similar problems for you: 1176 1087 1069 2084 1058
求连续递增最大子序列的和 ///特别sb的一个错误wa了一整版
#pragma warning(disable:4786)//使命名长度不受限制#pragma comment(linker, "/STACK:102400000,102400000")//手工开栈#include <map>#include <set>#include <queue>#include <cmath>#include <stack>#include <cctype>#include <cstdio>#include <cstring>#include <stdlib.h>#include <iostream>#include <algorithm>#define rd(x) scanf("%d",&x)#define rd2(x,y) scanf("%d%d",&x,&y)#define rds(x) scanf("%s",x)#define rdc(x) scanf("%c",&x)#define ll long long int#define maxn 200050#define mod 1000000007#define INF 0x3f3f3f3f //int 最大值#define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;++i)#define MT(x,i) memset(x,i,sizeof(x))#define PI acos(-1.0)#define E exp(1)using namespace std;int dp[maxn],a[maxn],st,ed,maxx;int main(){ int loop,n,cnt=1; rd(loop); while(loop--){ rd(n); FOR(i,1,n)rd(a[i]);MT(dp,0); dp[1]=a[1]; FOR(i,2,n) dp[i]=max(a[i],dp[i-1]+a[i]); maxx=dp[1];ed=1; FOR(i,1,n)if(dp[i]>maxx){ed=i;maxx=dp[i];} int s=0; for(int i=ed;i>0;i--){ s+=a[i]; if(s==maxx)st=i; } printf("Case %d:\n%d %d %d\n",cnt++,maxx,st,ed);////maxx打成了s 太傻逼了 if(loop)putchar('\n'); } return 0;}/*25 6 -1 5 4 -77 0 6 -1 1 -6 7 -5*/
0 0
- HDU 1003 Max Sum
- hdu 1003 Max Sum
- hdu 1003 Max Sum
- HDU-1003 max sum
- HDU 1003 - Max Sum
- HDU 1003 Max Sum
- hdu 1003 Max Sum
- HDU 1003 Max Sum
- HDU 1003 Max Sum
- hdu 1003 max sum
- HDU 1003 Max Sum
- hdu 1003 Max Sum
- HDU 1003 Max Sum
- hdu 1003 Max Sum
- HDU 1003 Max Sum
- Hdu 1003 - Max Sum
- HDU-1003-Max Sum
- hdu - 1003 - Max Sum
- postgresql 存储过程 把一个表的部分数据插入另一个表中(条件:传入的某些参数作为检索条件并且可能为空值)
- 视图控制器的一些方法的执行顺序
- 【ZOJ 3690】 Choosing number (矩阵快速幂)
- 杭电ACM2016-数据的交换输出
- 调整SQLServer2000运行中数据库结构
- HDU 1003 Max Sum
- MySQL数据导入导出全解
- Session和Cookie
- iOS Swift+Foundation学习笔记
- 学习openstack(一)
- 单链表
- POJ 3579:Median 差值的中位数
- error LNK1281: 无法生成 SAFESEH 映像VS2013常见编译错误解决
- hibernate 的class元素详解