当前位置:网站首页>Dynamic programming multiple knapsack celebration (one dimension)
Dynamic programming multiple knapsack celebration (one dimension)
2022-07-22 01:42:00 【Soldier Xiaobai】
Celebration party ( A one-dimensional )
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 .
Input format
Two numbers in the first line n,m, 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 I The price of each prize 、 value ( Price and value are different concepts ) And the maximum quantity you can buy ( buy 0 Pieces arrive at s Pieces can be ).
Output format
a line : a number , Indicates the maximum value that can be obtained from this purchase ( Be careful ! It's not the price ).
Data range
n≤500,m≤6000n≤500,m≤6000,
v≤100,w≤1000,s≤10v≤100,w≤1000,s≤10sample input :
5 1000 80 20 4 40 50 9 30 50 7 40 30 6 20 20 1
sample output :
1040
#include <bits/stdc++.h>
using namespace std;
const int M = 6010;
int n, m;
int f[M];
int main()
{
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; i ++)// The first dimension traverses the types of items from small to large ( Number of prizes )
{
int v, w, s;// Volume ( Price )、 value ( take max)、 Number
scanf("%d%d%d", &v, &w, &s);
for(int j = m; j >= v; j --)// The second dimension traverses the backpack capacity from large to small ( Appropriation amount )
for(int k = 0; k <= s && k * v <= j; k++)// The third dimension traverses the number from small to large
f[j] = max(f[j], f[j - k * v] + k * w);
}
printf("%d", f[m]);
return 0;
}
边栏推荐
- English语法_指示代词 this / these / that / those
- OSPF知识总结
- Payment system - reconciliation system
- (转帖)BeanFactory和FactoryBean的区别和联系
- Pipeline operators in mongodb ($group, $unwind, $sort, $limit, $skip)
- [paper reading] deep video analog detection: opportunities and challenges
- go gorm mysql报错:Error 1292: Incorrect datetime value: ‘XXX‘ for column ‘created_at‘ at row 1
- 企业电表数据采集 局域网本地存储软件系统
- Strict location dependent optimization of dynamic recursion
- When Lenovo Xiaoxin Air13 Pro reinstalls win10, the storage device driver cannot be found
猜你喜欢
随机推荐
动态规划例题——潜水员
Unity 之UGUI Text组件坚排显示(改进)
AidLux
Go Gorm MySQL reports an error: error 1292: incorrect datetime value: 'xxx' for column 'created_ at‘ at row 1
乘风破浪,金融科技时代下的数字化转型之路
Idea running @test cannot be input from the console and is in the loading state
The second financial article failed
Payment system - reconciliation system
【集训DAY8】Tent【数学】【DP】
JVM 内存布局详解,图文并茂,写得太好了!
06-1、友元、初始化列表初始化、nei‘bu
04-1、默认成员函数:构造函数、析构函数
Easyexcel realizes file upload - batch insert file download
Hardcore Fiddler packet capturing tool large strategy (end) Fiddler ultimate
Jupyterhub configuring go environment
tinymce 去掉编辑器换行默认增加的p标签
Configuration and use of kaptcha verification code
新知识经济时代,谁在生产知识?
Stream流中的Map与flatMap的区别
Codeforces Round #805 A-F题解