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

为什么用double错误的呢??虽然我的代码是笨了点,每年做一次背包

Posted by wyu_Onway at 2010-07-30 16:48:42 on Problem 2063
#include <iostream>
using namespace std;
int dp[100200],w[12],v[12];
int fmax(int a,int b)
{return a>b?a:b;}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int money,year,i,j,bond,k;
		double sum_money;

		scanf("%d%d",&money,&year);
		sum_money=money/1000.0;
		scanf("%d",&bond);

		for(i=1;i<=bond;++i)
		{
			scanf("%d%d",&w[i],&v[i]);
			w[i]/=1000;
		}

		while(year--)
		{
			memset(dp,0,sizeof(dp));
			k=(int)sum_money;
			for(i=1;i<=bond;++i)
				for(j=w[i];j<=k;++j)
					dp[j]=fmax(dp[j],dp[j-w[i]]+v[i]);
			sum_money+=dp[k]/1000.0;
		}
		money=(int)(sum_money*1000);

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