当前位置:网站首页>Knapsack problem of two-dimensional cost (01 knapsack)
Knapsack problem of two-dimensional cost (01 knapsack)
2022-07-22 01:42:00 【Soldier Xiaobai】
The knapsack problem of two-dimensional cost
Yes NN Items and a capacity are VV The backpack , The maximum weight a backpack can bear is MM.
Each item can only be used once . The volume is vivi, The weight is mimi, The value is wiwi.
Find out which items to pack in your backpack , It can make the total volume of the goods not exceed the capacity of the backpack , The total weight shall not exceed the maximum weight that the backpack can bear , And the sum of values is the largest .
Output maximum value .Input format
The first row has three integers ,N,V,MN,V,M, Space off , They represent the number of items 、 Backpack volume and maximum weight that backpack can bear .
Next there is NN That's ok , Three integers per row vi,mi,wivi,mi,wi, Space off , Separate indication control ii The volume of items 、 Weight and value .
Output format
Output an integer , Represents the greatest value .
Data range
0<N≤10000<N≤1000
0<V,M≤1000<V,M≤100
0<vi,mi≤1000<vi,mi≤100
0<wi≤10000<wi≤1000sample input
4 5 6 1 2 3 2 4 4 3 4 5 4 5 6
sample output :
8
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int n, V, M;
int f[N][N];
int main()
{
scanf("%d%d%d", &n, &V, &M);
for(int i = 1; i <= n; i ++)//01 Backpack first dimension
{
int v, m, w;
scanf("%d%d%d", &v, &m, &w);
for(int j = V; j >= v; j --)//01 Backpack 2D
for(int k = M; k >= m; k --)//01 Backpack 2D
f[j][k] = max(f[j][k], f[j - v][k - m] + w);
}
printf("%d", f[V][M]);
return 0;
}
边栏推荐
猜你喜欢
OSPF知识总结
Aruba学习笔记03-Web UI --Monitoring面板介绍
Stream流中的Map与flatMap的区别
Industrial control software - drive framework
huawei设置使用账号密码登录
Hardcore Fiddler packet capturing tool large strategy (end) Fiddler ultimate
Idea running @test cannot be input from the console and is in the loading state
项目实战四 图像拼接
使用CompletableFuture实现异步回调
[wechat applet] solve the problem that the code upload exceeds the size limit and the applet is subcontracted
随机推荐
[鹏城杯 2022] baby_re
[Yugong series] go teaching course in July 2022 014 arithmetic operators of operators
动态规矩-数组压缩优化
How to implement an asynchronous network library with go?
Easyexcel realizes file upload - batch insert file download
PYQT5打包出错,缺少文件,例ImportError: OpenCV loader: missing configuration file: [‘config.py‘]. Check
LeetCode 10. Regular Expression Matching
如何修改MySQL监听IP地址
动态递归之严格位置依赖优化
mysql8 貌似不支持myisam 分区表,PolarDB-X 支持myisam 的分区表吗?
【集训DAY6】Dream【优先队列】【贪心】
每个博主都需要问自己的7个基本问题
Uniapp, wechat applet input regular verification can only be input as numbers and decimal places
3. Project structure of source code analysis of Nacos configuration center
Apache Atlas 2.2版本安装
Idea running @test cannot be input from the console and is in the loading state
Unity_Demo | 中世纪风3D-RPG游戏
如何用Go实现一个异步网络库?
JVM memory layout detailed, illustrated, well written!
Learning path PHP -- thinkphp5 + windows server to achieve scheduled tasks