当前位置:网站首页>Class notes (3) example (2) -567 Beanfeast
Class notes (3) example (2) -567 Beanfeast
2022-07-16 04:58:00 【xyc20120615】
Description
In order to celebrate the class's first place in the school sports meeting , The head teacher decided to hold a celebration meeting , For this purpose, allocate funds to buy prizes to reward athletes . It is expected that the allocation amount can buy the most valuable prize , It can replenish their energy and physical strength .
Format
Input
Two numbers in the first line n (n≤500),m (m≤6000), among n Represents the number of prizes you want to buy ,m Indicates the appropriation amount .
Next n That's ok , Each row 3 Number ,v、w、s, Separate indication control ii The price of each prize 、 value ( Price and value are different concepts ) And the number of purchases ( buy 0 Pieces arrive at s Pieces can be ), among v≤100,w≤1000,s≤10.
Output
a number , Indicates the maximum value that can be obtained from this purchase ( Be careful ! It's not the price ).
Samples
input data 1
5 1000
80 20 4
40 50 9
30 50 7
40 30 6
20 20 1
Output data 1
1040
Limitation
1s, 1024KiB for each test case.
Answer key :
This is a classic multiple knapsack problem , Thinking table ~
With the formula in the table, plus three cycles and judgment conditions, it can be completed .
Program :
#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++){// Traverse n Items
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;
}be without ? be without !
边栏推荐
- Explain the exercises in Chapter 3 of C language
- A solution to the problem of opening garbled codes on individual mobile web pages
- 水墨云怎么样?
- tensorflow 使用 深度学习(二)
- Fiddler and Charles intercept and modify requests and return values
- Differences between multithreading and multiprocessing (summary)
- 一个整数队列的偶数放在前面,奇数放后面且偶数奇数的相对位置不变
- Quickly teach you how to build a data-driven automated testing framework?
- Knowledge points of driving license subject
- 如何编写有效的接口测试?
猜你喜欢

视频孪生:智慧园区信息化升级的抓手
![[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

鸟哥谈云原生安全最佳实践 | 文末赠书

从矩阵中查找数字是否存在

番茄定时调光台灯触摸芯片-DLT8T10S-杰力科创

没死,乐视还有400名员工:神仙赚钱手段曝光

User defined type explanation (structure, enumeration, Union)

fiddler和charles拦截并修改请求和返回值

上课笔记(3)例题(2)——#567. 庆功会(beanfeast)

opencv的实战学习之信用卡识别(四)
随机推荐
PHP basics explain PHP Basics
Database-Trivial
ObjectARX select entities to create block references
Comment écrire des tests d'interface efficaces?
【路由优化】基于生物地理学优化的 HWSN 节能聚类协议附matlab代码
[underlying principle] what is a socket? Why is the network inseparable from socket?
【回归预测-LSTM】基于attention机制的LSTM实现时间序列回归预测附matlab代码
Quickly teach you how to build a data-driven automated testing framework?
Knowledge points of driving license subject
php基础知识讲解 php基础
Applet container technology greatly improves the development efficiency of hybrid apps
【数字识别】基于知识库实现手写体数字识别附matlab代码
PyTorch - 存储和加载模型
【探究为什么String类是不可变类型:String类仿写】
如何理解套接字的形容词前缀:“面向连接”与“无连接”
Common tools and test methods for interface testing
Random类生成随机数详解
C language comprehensive training - address book (using dynamic memory)
测试如何发挥更大价值?聊聊测试左移和测试右移
看看谷歌如何在目标检测任务使用预训练权值 | CVPR 2022