HDU 1003 Max Sum 最大连续上升和
来源:互联网 发布:mac u盘启动盘制作 编辑:程序博客网 时间:2024/06/05 00:44
Max Sum
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 139206 Accepted Submission(s): 32328
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
/*HDU 1003 最长上升序列和 用len1 len2表示起始结束的位置 */#include <iostream>using namespace std;int a[100001];int main(){ int n,m,i,max,sum,len1,len2,k,j; cin>>m; k=1; while (m--) { scanf("%d",&n); max=-1001; sum=0; len1=1; len2=1; for(i=0;i<n;i++) { scanf("%d",&a[i]); if(sum<0) sum=a[i];//正的就往上加 else sum+=a[i]; if(sum>max) { max=sum; len2=i+1; } } for(j=0;j<n;j++) { sum=0; for(i=j;i<len2;i++) sum+=a[i]; if(sum==max) { len1=j+1; break; } } printf("Case %d:\n",k++); printf("%d %d %d\n",max,len1,len2); if(m!=0) printf("\n"); } return 0;}
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(dp,最大连续子序列和)
- HDU 1003 MAX SUM 最大连续子段和DP
- HDU 1003 Max Sum(dp,最大连续子序列和)
- HDU 1003 Max Sum 最大连续和 分治法
- HDU 1003----Max Sum(最大连续子序列和)
- HDU 1003 Max Sum(最大连续子段和)
- HDU 1003 Max Sum 最大连续子序列和
- 【最大连续子序列和dp】hdu 1003 Max Sum
- Android图片的一些操作
- HDU 2604 Queuing 递推
- Android中Toast的用法简介
- How to get your all bugs resolved without any ‘Invalid bug’ label?
- 自定义JS字符串全局替换函数replaceAll
- HDU 1003 Max Sum 最大连续上升和
- Android的ScrollView中添加自定义View
- HDU 1824 Let's go home(2-SAT)
- 企业数通知识系列之四--DHCP v6介绍
- 深圳—驾考
- HDU 1159 Common Subsequence 最大公共子序列
- linux tr命令
- url中携带中文的部分情况分析
- 计算房贷 公积金贷款 自由还款 程序