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 hdjtdxacm at 2009-03-15 15:19:42 on Problem 2533
#include<stdio.h>
int a[1001],dp[1001];
int main()
{
	int n,i,j,max;
	scanf("%d",&n);
	for(i = 1;i <= n;i++)
		scanf("%d",&a[i]);
	dp[1] = 1;max = 1;
	for(i = 2;i <= n;i++)
	{
		if(a[i] > a[i-1])
	    	dp[i] = dp[i-1] + 1;
		else
		{
			for(j = i - 1;j >= 1;j--)
			{
		    	if(a[i]>a[j])
				{
					dp[i] = dp[j]+1;
					break;
				}
			}
		}
	//	printf("%d %d\n",i,dp[i]);
		if(dp[i]>max)
			max = dp[i];
	}
	printf("%d\n",max);
	return 0;
}/*Sample Input

7
1 7 3 5 9 4 8
Sample Output

4
*/

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