当前位置:网站首页>上课笔记(3)例题(2)——#567. 庆功会(beanfeast)
上课笔记(3)例题(2)——#567. 庆功会(beanfeast)
2022-07-13 16:58:00 【xyc20120615】
Description
为了庆贺班级在校运动会上取得全校第一名成绩,班主任决定开一场庆功会,为此拨款购买奖品犒劳运动员。期望拨款金额能购买最大价值的奖品,可以补充他们的精力和体力。
Format
Input
第一行二个数 n (n≤500),m (m≤6000),其中 n 代表希望购买的奖品的种数,m 表示拨款金额。
接下来 n 行,每行 3 个数,v、w、s,分别表示第 ii 种奖品的价格、价值(价格与价值是不同的概念)和购买的数量(买 0 件到 s 件均可),其中 v≤100,w≤1000,s≤10。
Output
一个数,表示此次购买能获得的最大的价值(注意!不是价格)。
Samples
输入数据 1
5 1000
80 20 4
40 50 9
30 50 7
40 30 6
20 20 1
输出数据 1
1040
Limitation
1s, 1024KiB for each test case.
题解:
这是一道经典的多重背包问题,思考表格献上~
用上表格里的公式再加上三循环和判断条件就可以完成了。
程序:
#include<bits/stdc++.h>
using namespace std;
int m,n,a[510],w[510],c[510],dp[6010];
int main(){
cin>>n>>m;
for(int i=1;i<=n;++i)
cin>>w[i]>>c[i]>>a[i];
for(int i=1;i<=n;i++){//遍历n个物品
for(int j=m;j>=w[i];j--){
for(int k=0;k<=a[i];k++){
if(j-k*w[i]<0)
break;
dp[j]=max(dp[j],dp[j-k*w[i]]+k*c[i]);
}
}
}
cout<<dp[m];
return 0;
}没了?没了!
边栏推荐
猜你喜欢

Oracle本地网络服务

信息系统项目管理师必背核心考点(四十一)风险管理计划

测试/开发程序员的薪资不平衡?忙碌生活各种跳槽......

目标检测

(PC+WAP)织梦模板智能家居生活类网站
![[number recognition] handwritten number recognition based on knowledge base with matlab code](/img/06/6adab955a339f453249543baab1dc6.png)
[number recognition] handwritten number recognition based on knowledge base with matlab code

Digital collections are so hot that young people are running out of them

An article takes you to know about state-owned enterprise programmers (super detailed)

螺旋矩阵

【一知半解】AQS
随机推荐
微信小程序测试点汇总
你当程序员的原因是?有人因为穷,有人为梦想,而我却是……
Expert, Alibaba Daniel quit and brought out the internal "high concurrency system design" learning manual
电脑文件夹无法重命名怎么办?
FLASH W74M12JWSSIQ_ W25q64fwzpig specification, memory
SQL 2008 数据库迁移
接口测试常用工具及测试方法
Fumin County Science and Technology Association actively carries out emergency science popularization of safe edible wild fungi
一个描述机器学习对温室气体排放影响的系统框架
The color emission point of JS event occurs
重磅:国产IDE发布,由阿里研发,完全开源(高性能+高定制性)
多线程和多进程的差别(小结)
[mqtt from getting started to improving | 05] mqtt3.1.1 publish publishing workflow
Usage of Object-C @property
这个地图资源除了NB我不知道该说什么
数字藏品大热,年轻人快不够用了
enum类
Browser executes JS process
Oracle本地网络服务
Procedural life: I'm 29 this year, and I'm taking the career change test. How can I get four offers in a week?