[Max Sum]hdu 1003

Water ~

 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdio>
 4
 5 using namespace std;
 6 const int INF=100000000;
 7
 8 int t,n,a;
 9 int main()
10 {
11     cin>>t;
12     for(int i=1;i<=t;i++){
13         cin>>n;
14         int sum=0;
15         int max=-INF;
16         int l=1,left=1,right=1;
17
18         for(int j=1;j<=n;j++){
19             cin>>a;
20             sum+=a;
21             if(sum>max){
22                 right=j;
23                 left=l;
24                 max=sum;
25             }
26             else if(sum<0){ // can not be "else if" !
27                 sum=0;
28                 l=j+1;
29             }
30         }
31         if(i!=1)printf("\n");
32         printf("Case %d:\n",i );
33         printf("%d %d %d\n",max,left,right );
34     }
35     return 0;
36 } 
时间: 2024-12-14 21:09:02

[Max Sum]hdu 1003的相关文章

HDU OJ Max sum 题目1003

 #include <iostream> #include<stdio.h> #include<stdlib.h> using namespace std; int main() { int t; scanf("%d",&t); for(int i=0;i<t;i++) { int n; scanf("%d",&n); int sum=0,max=-99999; int curhead=1,rear=1,

HDU 1003 Max Sum &amp;&amp; HDU 1231 最大连续子序列 (DP)

Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 154155    Accepted Submission(s): 35958 Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max su

A-max sum &lt;HDU 1003&gt;

A-max sum 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. InputThe first line of the input contains an integer

HDU 1003 Max Sum【动态规划求最大子序列和详解 】

Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 250714    Accepted Submission(s): 59365 Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max su

HDU 1003 Max Sum(最大子列和)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003 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

sum max(hdu 1003)

观察可以发现,0,1,2,--,n结尾的分组中, maxsum a[0] = a[0] maxsum a[1] = max( a[0] + a[1] ,a[1])  = max( maxsum a[0] + a[1] ,a[1]) maxsum a[2] = max( max ( a[0] + a[1] + a[2],a[1] + a[2] ),a[2]) = max(  max( a[0] + a[1] ,a[1]) + a[2] , a[2]) = max(  maxsum a[1] + a

HDU - 1003 - Max Sum &amp;&amp; POJ - 1050 - To the Max (经典DP问题)

题目传送:HDU - 1003 思路:最大子序列和 dp[i]= a[i]   (dp[i-1]<0) dp[i]= dp[i-1]+a[i]   (dp[i-1]>=0) AC代码: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <cmath> #include <queue> #include

HDU 1003 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

HDU 1003:Max Sum(DP)

Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 142742    Accepted Submission(s): 33225 Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max s