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

while(brick[left[i]-1]>=brick[i])可能死掉,注意边界条件。

Posted by zhucheng at 2005-08-13 10:03:12 on Problem 2559
In Reply To:在论坛上学的DP,却总是TLE,恳请高人指点!! Posted by:jiali at 2005-08-13 09:20:28
> 这是我的代码
> #include<stdio.h>
> int left[100005],right[100005],i,j,k,n;
> __int64 brick[100005]={0},max,l;
> int main(int argc, char* argv[])
> {
>     while(scanf("%d",&n)>0)
>     {
>         if(n==0) break;
>         for(i=1;i<=n;i++)
>         {
>             scanf("%I64d",&brick[i]);
>             left[i]=right[i]=i;
>         }
>         brick[i+1]=brick[0]=0;
>         for(i=1;i<=n;i++)
>         {
>             while(brick[left[i]-1]>=brick[i])
>             {left[i]=left[left[i]-1];}
>         }
>         for(i=n;i>=1;i--)
>         {
>             while(brick[right[i]+1]>=brick[i])
>             {right[i]=right[right[i]+1];}
>         }
>         max=0;
>         for(i=1;i<=n;i++)
>         {
>             l=right[i]-left[i]+1;
>             if(l*brick[i]>max)
>             {
>                 max=l*brick[i];
>             }
>         }
>         printf("%I64d\n",max);
>     }
>     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