hdu 1003(最大连续子序列和)
来源:互联网 发布:编程用什么配置的电脑 编辑:程序博客网 时间:2024/05/17 22:45
Max Sum
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 132525 Accepted Submission(s): 30717
Problem DescriptionGiven 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.
InputThe 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).
OutputFor 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 Input25 6 -1 5 4 -77 0 6 -1 1 -6 7 -5
Sample OutputCase 1:14 1 4Case 2:7 1 6
25 6 -1 5 4 -77 0 6 -1 1 -6 7 -5
Case 1:14 1 4Case 2:7 1 6
#include <cstdio>int main(){ freopen("input.txt","r",stdin); int n,T,num,sum,max,t,l,r; scanf("%d",&T); int cas=1; while(T--) { sum=0; max=-1<<30;t=l=r=1; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",&num); if(sum<0){sum=num;t=i;} else sum+=num; if(sum>max){max=sum,l=t,r=i;} } printf("Case %d:\n%d %d %d\n",cas++,max,l,r); if(T)printf("\n"); } return 0;}
0 0
- hdu 1003 最大连续子序列和
- HDU 1003 Max Sum(最大连续子序列和)
- hdu 1003(最大连续子序列和)
- HDU 1003----Max Sum(最大连续子序列和)
- 最大和连续子序列(Hdu 1003)
- 【HDU】 1003 Max Sum(最大连续子序列和)
- 最大连续子序列和(经典DP) 之 hdu 1231 最大连续子序列
- hdu 1231 最大连续子序列和
- hdu 5586(最大连续子序列和)
- HDU 1231 最大连续子序列和
- HDU 1231 最大连续子序列(最大连续子段和)
- POJ 1050,HDU 1003 最大连续子序列和
- hdu 1003 MAX SUM(最大连续子序列和)
- HDU 1003 Max Sum 最大连续子序列的和
- HDU 1003 Max Sum(dp,最大连续子序列和)
- HDU 1003 Max Sum(dp,最大连续子序列和)
- hdu 1003 1231 最大连续子序列的和
- HDU 1003 Max Sum 最大连续子序列和
- 如何学习编程
- bridge ip
- MVC模式在游戏开发的应用
- 关闭SSD(固态硬盘)节能功能 提搞SSD性能
- POJ2065_Testing the CATCHER_DP
- hdu 1003(最大连续子序列和)
- Android记事本开发
- 利用OpenCV鼠标控制窗口大小
- 解决方案~Microsoft Security Client OOBE 程序错误
- C++ STL inner_product
- POJ1860_钉子小球_DP
- 排序算法之二-选择排序和插入排序
- 佛學與編程 (楞嚴經)
- POJ1157_LITTLE SHOP OF FLOWERS_DP