Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

你多虑了

Posted by zjut020 at 2009-03-11 22:35:05 on Problem 2593 and last updated at 2009-03-11 22:35:32
In Reply To:此题与2479不是一回事 Posted by:kurtcq at 2008-10-03 20:31:54
你多虑了。。数据卡的不一样而已。该代码都可ac(输入改下)
#include<iostream>
#include<fstream>
using namespace std;
int main()
{ 
   //ifstream cin("0.txt");
    
    int n,aa[100000],i,j,dp[100000];
    while(scanf("%d",&n)!=EOF&&n)
    {
        for(i=0;i<n;i++)scanf("%d",aa+i);
         int sum=0,max=aa[0];
         for(i=0;i<n;i++)
         {
              sum+=aa[i];
              if(sum>max)
              max=sum;
              dp[i]=max;
              if(sum<0)
              sum=0;               
         }sum=0,max=aa[n-1];int _max=-1000000;
         for(i=n-1;i>0;i--)
         {
              sum+=aa[i];
              if(sum>max)
              max=sum;
              if(_max<max+dp[i-1])
              _max=max+dp[i-1]; 
              if(sum<0)
              sum=0;     
         }
         printf("%d\n",_max);     
    }
   // system("pause");
    return 0;  
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator