当前位置:网站首页>Why should a complete knapsack be traversed in sequence? Briefly explain
Why should a complete knapsack be traversed in sequence? Briefly explain
2022-07-07 00:00:00 【Fairy Tales】
Complete backpack means that each item can be put into the backpack many times .
dp[j] = max(dp[j], dp[j - weight[i]] + value[i])
dp[6] = max(dp[6], dp[6 - 1] + 2)
= max(dp[6], max(dp[5], dp[5 - 1] + 2) + 2)
dp[j] The capacity is j The maximum value of your backpack with items .
1 It means the first one i The weight of each item ,2 It means the first one i The value of an article .
Initial dp[5] and dp[6] All for 0.
here , Because initially dp[6] yes 0, So I must have chosen dp[6 - 1] + 2, That is to say, it must have been put into No i Items .
and dp[6]=…… The implementation of requires dp[5] Result .
Because it is executed sequentially , therefore dp[6] It must have been implemented before implementation dp[5]=…….
dp[5]=…… Execution time , Because initially dp[5] yes 0, So I must have chosen dp[5 - 1] + 2, That is to say, it must also be put into No i Items .
So the first i Items have been put in many times .
So the complete knapsack should be traversed in sequence .
边栏推荐
- How to use vector_ How to use vector pointer
- app通用功能測試用例
- openresty ngx_lua子请求
- 在Docker中分分钟拥有Oracle EMCC 13.5环境
- App general function test cases
- DAY ONE
- Please help xampp to do sqlilab is a black
- leetcode:236. 二叉树的最近公共祖先
- 17、 MySQL - high availability + read / write separation + gtid + semi synchronous master-slave replication cluster
- DAY ONE
猜你喜欢
STM32 enters and wakes up the stop mode through the serial port
MVC and MVVM
达晨史上最大单笔投资,今天IPO了
服务器SMP、NUMA、MPP体系学习笔记。
Automatic test tool katalon (WEB) test operation instructions
iMeta | 华南农大陈程杰/夏瑞等发布TBtools构造Circos图的简单方法
快讯 l Huobi Ventures与Genesis公链深入接洽中
DAY FIVE
从外企离开,我才知道什么叫尊重跟合规…
【2022全网最细】接口测试一般怎么测?接口测试的流程和步骤
随机推荐
Introduction au GPIO
Gold three silver four, don't change jobs
17、 MySQL - high availability + read / write separation + gtid + semi synchronous master-slave replication cluster
app通用功能测试用例
GPIO簡介
Pytest multi process / multi thread execution test case
Design a red envelope grabbing system
How to use vector_ How to use vector pointer
【精品】pinia 基于插件pinia-plugin-persist的 持久化
STM32通过串口进入和唤醒停止模式
Server SMP, NUMA, MPP system learning notes.
SQL的一种写法,匹配就更新,否则就是插入
MATLIB reads data from excel table and draws function image
(leetcode) sum of two numbers
内网穿透zerotier 外网(手机、电脑等)访问内网设备(树莓派、NAS、电脑等)
Local deployment Zeppelin 0.10.1
谷歌百度雅虎都是中国公司开发的通用搜索引擎_百度搜索引擎url
Tourism Management System Based on jsp+servlet+mysql framework [source code + database + report]
零代码高回报,如何用40套模板,能满足工作中95%的报表需求
[unmanned aerial vehicle] multi unmanned cooperative task allocation program platform, including Matlab code