1019. 庆功会(多重背包问题)

活动 - AcWing

为了庆贺班级在校运动会上取得全校第一名成绩,班主任决定开一场庆功会,为此拨款购买奖品犒劳运动员。

期望拨款金额能购买最大价值的奖品,可以补充他们的精力和体力。

输入格式

第一行二个数n,m,其中n代表希望购买的奖品的种数,m表示拨款金额。

接下来n行,每行3个数,v、w、s,分别表示第I种奖品的价格、价值(价格与价值是不同的概念)和能购买的最大数量(买0件到s件均可)。

输出格式

一行:一个数,表示此次购买能获得的最大的价值(注意!不是价格)。

数据范围

n≤500,m≤6000

v≤100,w≤1000,s≤10

输入样例:
复制代码
5 1000
80 20 4
40 50 9
30 50 7
40 30 6
20 20 1
输出样例:
复制代码
1040

解析: ​​​​​​P1776 宝物筛选(多重背包模板题)-CSDN博客

cpp 复制代码
#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<math.h>
#include<map>
#include<sstream>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
const int N = 8e2+10, M = 1e5 + 10;
const int INF = 1e8;
int n,m;
int vv[M], ww[M];
int f[M];

int main() {
	cin >> n >> m;
	int cnt = 0;
	for (int i = 1,v,w,s; i <= n; i++) {
		scanf("%d%d%d", &v, &w, &s);
		int t = 1;
		while (s >= t) {
			vv[++cnt] = t*v;
			ww[cnt] = t*w;
			s -= t;
			t *= 2;
		}
		if (s > 0) {
			vv[++cnt] = s * v;
			ww[cnt] = s * w;
		}
	}
	for (int i = 1; i <= cnt; i++) {
		for (int j = m; j >= vv[i]; j--)f[j] = max(f[j], f[j - vv[i]] + ww[i]);
	}
	cout << f[m] << endl;
	return 0;
}
相关推荐
.格子衫.15 分钟前
022数据结构之树状数组——算法备赛
数据结构·算法·1024程序员节
黑科技Python27 分钟前
生活中的“小智慧”——认识算法
学习·算法·生活
sali-tec1 小时前
C# 基于halcon的视觉工作流-章52-生成标定板
开发语言·图像处理·人工智能·算法·计算机视觉
IT古董1 小时前
【第五章:计算机视觉-项目实战之推荐/广告系统】2.粗排算法-(4)粗排算法模型多目标算法(Multi Task Learning)及目标融合
人工智能·算法·1024程序员节
熬了夜的程序员1 小时前
【LeetCode】89. 格雷编码
算法·leetcode·链表·职场和发展·矩阵
對玛祷至昏2 小时前
数据结构理论知识
数据结构·算法·排序算法
oliveira-time2 小时前
二分搜索(Binary Search)
算法
王哈哈^_^3 小时前
【数据集】【YOLO】【目标检测】口罩数据集,口罩佩戴识别数据集 1971 张,YOLO佩戴口罩检测算法实战训练教程。
人工智能·算法·yolo·目标检测·计算机视觉·ai·视觉检测
dragoooon344 小时前
[优选算法专题四.前缀和——NO.31~32 连续数组、矩阵区域和]
数据结构·算法·leetcode·1024程序员节
py有趣4 小时前
LeetCode算法学习之移除元素
java·数据结构·算法