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

贴个挺慢的AC代码,400+MS

Posted by speedcell4 at 2012-02-23 11:01:33 on Problem 2479
#include<iostream>

using namespace std;

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

const int MAXN = 52000;
int tcase,n,ans,a[MAXN],dp1[MAXN],dp2[MAXN];

int main()
{
    scanf("%d",&tcase);while(tcase--)
    {
        scanf("%d",&n);
        for(int i=1;n-i>=0;i++) scanf("%d",&a[i]);
        
        memset(dp1,0,sizeof(dp1));
        memset(dp2,0,sizeof(dp2));
        
        for(int i=1;n-i>=0;i++) dp1[i]=max(a[i],dp1[i-1]+a[i]);
        for(int i=n;i-1>=0;i--) dp2[i]=max(a[i],dp2[i+1]+a[i]);
        
        for(int i=2;n-i>=0;i++) dp1[i]=max(dp1[i],dp1[i-1]);
        for(int i=n-1;i>=1;i--) dp2[i]=max(dp2[i],dp2[i+1]);
        
        ans=dp1[1]+dp2[2];
        for(int i=2;n-i>=0;i++) ans=max(ans,dp1[i-1]+dp2[i]);
        printf("%d\n",ans);
    }
    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