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

求解,代码如下,老是RE,数组开大了就超内存。求高手解答

Posted by 3110402077 at 2012-10-22 21:28:23 on Problem 2063
#include <stdio.h>
typedef int count;
typedef struct 
{
	int a;
	int b;
}m;
m a[15];
int dt[3000000];
int year,d;

int dp (int sum)
{
	int i=0,max=0;
	if(dt[sum]!=0)
		return dt[sum];
	for (i=0;i<d;i++)
	{
		if(sum-a[i].a>=0)
		{
			dt[sum-a[i].a]=dp(sum-a[i].a);
			if(dt[sum-a[i].a]+a[i].b>max)
				max=dt[sum-a[i].a]+a[i].b;
		}
	}
	return max;
}

int main()
{
	int sum;
	count i,n;
	while(scanf("%d",&n)!=EOF)
	{
		while(n--)
		{
			for (i=0;i<3000000;i++)
					dt[i]=0;
			scanf("%d%d",&sum,&year);
			scanf("%d",&d);			//d为可行投资方案
			for (i=0;i<d;i++)
				scanf("%d%d",&a[i].a,&a[i].b);
			for (i=0;i<year;i++)
				sum += dp(sum);
			printf("%d\n",sum);
		}
	}
	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