HDU 1003 (最大子序列和)
来源:互联网 发布:js 构造函数 编辑:程序博客网 时间:2024/06/16 14:58
Max Sum
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#include <stdio.h>int main(){int t,j;scanf("%d",&t); for(j=1;j<=t;j++){int n,i;int sum=0,max=-2000,start=1,temp=1,end;scanf("%d",&n);int a[n+1];for(i=1;i<=n;i++){ scanf("%d",&a[i]); sum+=a[i]; if(max<=sum) { start=temp; max=sum; end=i; } if(sum<0){ sum=0; temp=i+1; }}printf("Case %d:\n%d %d %d\n",j,max,start,end);if(j!=t)printf("\n");}}
阅读全文
0 0
- HDU 1003(最大子序列和)
- hdu 1003 求最大子序列和
- hdu 1003 求最大子序列和
- hdu 1003 最大子序列的和
- hdu 1003 最大连续子序列和
- HDU 1003子序列最大和
- HDU 1003 (最大子序列和)
- HDU 1003(最大子序列和)
- HDU 1003 最大子序列
- hdu 1003 最大子序列和 简单题
- HDU 1003 Max Sum(最大连续子序列和)
- POJ 1050,HDU 1003 最大连续子序列和
- HDU-1003-动规-最大子序列和
- hdu 1003 Max Sum (求最大子序列和)
- hdu 1003(最大连续子序列和)
- hdu 1003 MAX SUM(最大连续子序列和)
- HDU 1003 Max Sum 最大连续子序列的和
- HDU 1003 Max Sum(dp,最大连续子序列和)
- ReactNative 网络请求服务方式
- zabbix监控第一台主机系统
- Python易错点整理——for和else的搭配使用、global的使用
- Git实例学习
- 复制表
- HDU 1003 (最大子序列和)
- 关于 stl map 的 []操作符问题
- HDUOJ 水果
- 【poj3630】Phone List 【Nordic 2007】
- 网卡驱动程序
- 数据结构树
- POJ3468 A Simple Problem with Integers(线段树区间更新,lazy标记)
- 01QT编写自己的UC浏览器-编写带标题栏和Aero效果的浏览器框架
- 度度熊的午饭时光 百度之星