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为何始终wa啊!!!

Posted by wocha at 2012-07-18 10:02:46 on Problem 3903
#include<stdio.h>
#include<string.h>
int a[200000];
int dp[400000];
int main()
{
	int n;
	while(~scanf("%d",&n))
	{
        if(n<=0) break;
        memset(dp,0,n+3);
		for(int j=0;j<n;j++)
		{
			
			scanf("%d",&a[j]);	
		}
		dp[0]=1;
		int i,j;
		for( j=1;j<n;j++)
		{
            if(a[j]>a[j-1]) dp[j]=dp[j-1]+1;
            else if(a[j]==a[j-1]) dp[j]=dp[j-1];
            else 
            {
            for(i=0;i<j;i++)
              {
                    if(a[j]==a[i])
                   {
                     dp[j]=dp[i];
                     break;
                    }
                if(a[j]>a[i]&&a[j]<a[i+1])
                {
                     dp[j]=dp[i]+1;
                     break;
                }
                
                
              }
              if(i==j) dp[j]=1;
            }
        }
        int m=-454545;
        for( i=0;i<n;i++)
           {
                if(m<dp[i])
                 m=dp[i];
            }
         printf("%d\n",m);
	}
}

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