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

这题挺简单的,完全背包,注意钱数÷1000

Posted by ACAccepted at 2019-03-17 09:21:22 on Problem 2063 and last updated at 2019-03-17 09:24:02
#include <cstdio>
#include <cstring>
using namespace std;

int max(int a,int b)
{
	return (a>b)?a:b;
}

int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0' || c>'9'){if (c=='-')f=-1;c=getchar();}
	while (c>='0'&&c<='9'){x=(x<<1)+(x<<3)+c-48;c=getchar();}
	return x*f;
}

const int MAXN=10000;
const int MAXM=50000;
int m,v,n;
int f[MAXM];
int a[MAXN],b[MAXN];

int main()
{
	int cas;cas=read();
	while (cas--)
	{
		m=read();v=read();n=read();
		for (int i=1;i<=n;i++)
			a[i]=read(),b[i]=read();
		int ans=0,most=m;
		for (int k=1;k<=v;k++)
		{
			memset(f,0,sizeof(f));
			for (int i=1;i<=n;i++)
			{
				for (int j=(a[i]/1000);j<=(most/1000);j++)
					f[j]=max(f[j],f[j-(a[i]/1000)]+b[i]);
			}
			ans+=f[(most/1000)];most+=f[(most/1000)];
		}
		printf("%d\n",ans+m);
	}
	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