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

可以让背包当前的重量作为状态。

Posted by 1196494730 at 2018-08-12 14:35:43 on Problem 3624
#include<stdio.h>
struct bracelet
{
	int w;
	int v;
};
struct bracelet b[3410];
int dp[12990];
int n,m;
void main()
{
	int i,j;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)
	{
		scanf("%d%d",&b[i].w,&b[i].v);
	}
	for(i=1;i<=n;i++)
	{
		for(j=0;j+b[i].w<=m;j++)
		{
			if(dp[j]<dp[j+b[i].w]+b[i].v)
				dp[j]=dp[j+b[i].w]+b[i].v;
		}
	}
	printf("%d",dp[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