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

跪求,坐等啊,多谢各位

Posted by tenlee2012 at 2014-08-24 22:51:46 on Problem 2533
#include<stdio.h>
#include<string.h>
#define MAX 1005
int dp[MAX], a[MAX];
int main()
{
	int n, i, j;
	while (~scanf("%d",&n))
	{
		for (i=0;i<n;i++)
		    scanf("%d",&a[i]);
		 memset(dp,0,sizeof(dp));
		int max = 0;
		for (i=0;i<n;i++)
		{
			for (j=i+1;j<n;j++)
			{
				if (a[j] > a[i])
				{
					dp[j] = dp[j]>(dp[i]+1) ?
					dp[j] : (dp[i]+1);
				}
			    if (dp[j] > max)
			        max = dp[j];
			    // printf("%d\n",dp[j]);
			}
		}
		printf("%d\n",max+1);
	}
	return 0;
}
					
这样求最长上升子序列可以吗?为什么有的时候WA了。。。如果不正确,跪求测试啊

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