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

Re:DP+二分查找,错哪了?

Posted by ccnujing at 2008-05-06 09:38:44 on Problem 2533
In Reply To:DP+二分查找,错哪了? Posted by:yiyiyi4321 at 2005-12-16 11:04:28
> #include<stdio.h>
> int a[5000],d[5000];
> main()
> {long i,n,len=0;
>  long mid,left,right;
>  scanf("%ld",&n);
>  for(i=0;i<n;i++)
>   scanf("%d",&a[i]);
>  for(i=0;i<n;i++)
>   {
>    if(a[i]>d[len])
>      d[++len]=a[i];
>    else {
> 	 left=1;
> 	 right=len;
> 	  while(left<right-1)
> 	 {
> 	  mid=(left+right)/2;
> 	  if(a[i]>d[mid])
> 	    left=mid+1;
> 	  if(a[i]<d[mid])
> 	    right=mid-1;
> 	  if(a[i]==d[mid])
> 	    break;
> 	 }
> 	  if(a[i]<d[left])d[left]=a[i];
> 	  else if(a[i]<d[right])d[right]=a[i];
>         }
>    }
>   printf("%d",len);
> }

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