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

求帮助!!WA!!结果都是正确的

Posted by coolman at 2013-11-27 12:10:45 on Problem 1276
#include <iostream>
using namespace std;

int dp[100001];
int max(int* a, int len, int n)
{
	int tmp = 0;
	for (int i=1; i<=len; i++)
	{
		if (tmp<a[i]) 
		{
			tmp = a[i];
			n = i;
		}
	}
	return tmp;
}

int main()
{
	int cash, N;
	while(scanf("%d%d",&cash,&N) != EOF)
	{
		//输入并初始化数据
		int* n = new int[N+1];
		int* D = new int[N+1];
		memset(dp, 0, sizeof(dp));
		memset(n, 0, (N+1)*sizeof(int));
		memset(D, 0, (N+1)*sizeof(int));
		for (int i=1; i<=N; i++)
			scanf("%d%d", n+i, D+i);

		//DP流程
		for (int i=0; i<=cash; i++)
		{
			int* tmp = new int[N+1];
			memset(tmp, 0, (N+1)*sizeof(int));

			//DP公式
			for (int j=1; j<=N; j++)
			{
				if ((n[j] > 0)&&(i >= D[j]))
					tmp[j] = dp[i-D[j]] + D[j];
			}
			int m=0;
			dp[i] = max(tmp, N, m);
			n[m]--;
			delete tmp;
		}
		printf("%d\n", dp[cash]);
		delete D;
		delete n;
	}

	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