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 hopeztm at 2012-08-14 17:27:42 on Problem 1260
#include <stdio.h>
#include <memory.h>

struct Pearl
{
	int prize;
	int nbuy;
};

Pearl allPearl[105];
int dp[105];
int nPearl;

int main()
{
	int ncase;

	scanf("%d", &ncase);

	while(ncase--)
	{
		scanf("%d", &nPearl);

		for( int i = 0; i < nPearl; i++)
		{
			scanf("%d%d", &allPearl[i].nbuy, &allPearl[i].prize);
		}

		dp[nPearl - 1] = allPearl[nPearl - 1].nbuy;
		int replace, minPrize = 100000000;


		int sum = (dp[nPearl - 1] + 10) * allPearl[nPearl-1].prize;


		for( int i = nPearl - 2; i >= 0; i--)
		{
			dp[i] = 0;
			minPrize = 100000000;

			for( int j = nPearl - 1; j >= i; j--)
			{
				int prize;
				if(dp[j] == 0)
				{
					prize = sum + (allPearl[i].nbuy + 10) * allPearl[j].prize;
				}
				else
				{
					prize = sum + (allPearl[i].nbuy ) * allPearl[j].prize;
				}
				
				if(prize < minPrize)
				{
					minPrize = prize;
					replace = j;
				}
			}
			dp[replace] += allPearl[i].nbuy;
			sum = minPrize;
		}
		

		printf("%d\n", sum);
	}

}

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