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

why wa????????????????

Posted by fresh_bird at 2012-12-06 16:54:51 on Problem 1276
#include<iostream>
#include<cstring>
using namespace std;
int dp[100001];
int myMax(int x,int y)
{
	return x>y?x:y;
}
void MultiPack(int cash,int nk,int dk)
{
	int i,k;
	if(nk*dk>=cash)
	{
		for(i=dk;i<=cash;i++)
			dp[i]=myMax(dp[i],dp[i-dk]+dk);
		return;
	}
	k=1;
	while(k<nk)
	{
		for(i=cash;i>=k*dk;i--)
			dp[i]=myMax(dp[i],dp[i-dk*k]+dk*k);
		nk-=k;
		k<<=1;
	}
	k=nk;
	for(i=cash;i>=k*dk;i--)
		dp[i]=myMax(dp[i],dp[i-dk*k]+dk*k);
}
int main()
{
	int cash,n,nk,dk;
	while(!cin.eof())
	{
		memset(dp,0,sizeof(dp));
		cin>>cash>>n;
		while(n)
		{
			cin>>nk>>dk;
			MultiPack(cash,nk,dk);
			n--;
		}
		cout<<dp[cash]<<endl;
	}
	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