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 cmh786 at 2012-02-22 20:01:46 on Problem 1260
#include <cstdlib>
#include <iostream>

using namespace std;

int k = 0;
int c = 0;
int a[1005];
int p[1005];
int dp[1005];

int find()
{
	memset(dp, 0, sizeof(dp));

	for(int i=0; i<c; i++)
	{
		dp[i] = a[i];
		for(int j=0; j<i; j++)
		{
			if(dp[j] > 0)
			{
				if((dp[j]+10)*p[j] > dp[j]*p[i])
				{
					dp[i] += dp[j];
					dp[j] = 0;					
				}
			}
		}
	}

	int sum = 0;
	for(int k=0; k<c; k++)
	{
		if(dp[k] > 0)
		{
			sum += (dp[k]+10)*p[k];
		}
	}
	return sum;
}

int main()
{
	scanf("%d", &k);

	while(k--)
	{
		scanf("%d", &c);

		for(int i=0; i<c; i++)
		{
			scanf("%d %d", &a[i], &p[i]);
		}

		printf("%d\n", find());
	}
	
	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