Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
你多虑了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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator