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 0_0123 at 2017-08-13 00:49:07 on Problem 3624
In Reply To:你们写代码都不写注释,这不是个好习惯,贴我的 Posted by:lafurose at 2017-04-15 11:31:37
#include<algorithm>
#include<iostream>
#include<cstdio>
using namespace std;
int N, M;            //N个物品,包的体积为M
int w[3505], d[3505];      //体积,价值
int result[13005] = {0};         //result[i]表示从从 某些物品 中取出体积为i的最大价值
int main()
{
	scanf("%d%d", &N, &M);
	for (int i = 1; i <= N; ++i)
		scanf("%d%d", &w[i], &d[i]);
	for (int i = 1; i <= N; ++i)            //从前i个物品取体积为j
		for (int j = M; j >= w[i]; --j)
			result[j] = max(result[j], result[j - w[i]] + d[i]);
	printf("%d\n", result[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