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 WonderStar at 2010-08-08 21:12:18 on Problem 3903
#include <iostream>
const int maxn=100000;
int price[maxn], d[maxn],L,best;
int dp(int i)
{
	int &ans=d[i];
	if(ans>0) return ans;
	ans=1;
	for(int j=i+1; j<L; j++)
		if(price[j]>price[i]) 
		{
			if(ans<dp(j)+1) ans=dp(j)+1;
		}
	return ans;
}
int main()
{
	freopen("A.IN","r",stdin);
	while(scanf("%d", &L)!=EOF)
	{
		best=1;
		for(int i=0; i<L; i++) scanf("%d",&price[i]);
		memset(d, -1, sizeof(d));
		for(int i=0; i<L; i++){ if(best<dp(i)) best=dp(i);}
		printf("%d\n", best);
	}
	system("pause");
	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