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

DP。。AC~贴代码

Posted by wsc500 at 2012-04-26 22:02:38 on Problem 2479
#include <stdio.h>
#include <stdlib.h>
#define bigger(a,b) (a>b?a:b)
int t;
int list[50000+2],fa[50000+2],fb[50000+2],fans[50000+2];
int main()
{
    scanf("%d",&t);
    for (int outi=0;outi<t;outi++)
    {
        int i,max,n;
        scanf("%d",&n);
        for (i=1;i<=n;i++)
            scanf("%d",&list[i]);
        fa[1]=list[1];
        fb[n]=list[n];
        for (i=2;i<=n;i++)
            fa[i]=bigger(list[i],fa[i-1]+list[i]);
        for (i=n-1;i>=1;i--)
            fb[i]=bigger(list[i],fb[i+1]+list[i]);
        fans[n]=fb[n];
        for (i=n-1;i>=1;i--)
            fans[i]=bigger(fans[i+1],fb[i]);
        max=-9999999;
        for (i=2;i<=n;i++)
            if (fans[i]+fa[i-1]>max)    max=fans[i]+fa[i-1];
        printf("%d\n",max);
        for (i=0;i<=n;i++)
            list[i]=fa[i]=fb[i]=fans[i]=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