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

大牛们,HELP

Posted by wangleinuts at 2007-05-23 14:13:16 on Problem 2738
请问为什么WA呢?谢谢
#include <stdio.h>
#include <string.h>
#include <math.h>
int tem,tem1,n,i,an[1002],dp[1002][1002],kth=1;
bool used[1002][1002];
int work(int x , int y)
{
	if(!used[x][y])
	{
		used[x][y] = true;
		if(y-x == 1)	dp[x][y] = abs(an[y] - an[x]) ;
		else
		{
			if(an[x+1] >= an[y])
				tem =  work(x+2,y) + an[x] -an[x+1];
			else 
				tem = work(x+1,y-1) + an[x] -an[y];
			if(an[x] >= an[y-1])
				tem1 = work(x+1,y-1) + an[y] - an[x];
			else
				tem1 = work(x , y-2) + an[y] - an[y-1];
			if(tem>tem1)	dp[x][y] = tem;
			else			dp[x][y] = tem1;
		}
	}
	return dp[x][y];
}
int main()
{
	while(scanf("%d",&n) && n)
	{
		memset(used,0,sizeof(used));
		for(i = 0 ; i < n ; i++)	scanf("%d",an+i);
		printf("In game %d, the greedy strategy might lose by as many as %d points.\n",kth++,work(0,n-1));
	}
	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