Comments (1)
对于 0-1 背包问题上的滑动数组写法时,我有一个自己的理解,不知道是否正确。
假设有物体 j 个,每个物体的价值为value[j],重量为weight[ j ],那么对于一个背包 dp[ i ]
可以知道
dp[ i ] = max{dp[ i ], dp[ i - weight[ j ] + value[ j ]]}相当于是说,这个背包可以由多个小背包推导出来,由哪几个小背包推导出来?就是 i - weight[ i ] 的这几个小背包,然后在里面挑选一个最大的值,初始化的过程应该也是相似的,即 dp[0] = 0;然后如果 i - weight[ i ] <= 0 说明没有这种小背包,直接continue;
您觉得这样理解可以吗~
可以啊,解释的话,只要自己容易理解就好,但我写文章一定是 普遍大家容易理解的角度来写
from leetcode-master.
Related Issues (20)
- 416. 分割等和子集dp数组大小问题的讨论
- 对称二叉树再勘误
- 21.解数独问题可以做优化
- 优化:关于其他语言版本的显示
- 0337.打家劫舍III 方法2:记忆化递推 时间复杂度的疑问
- 关于完全背包理论中遍历顺序的问题
- 勘误【栈与队列 2.用栈实现队列】
- 勘误动态规划26单词差分
- 回溯算法 3.组合优化 内容重复
- 0151. 反转字符串中的单词-时间复杂度
- 这里没写好 HOT 1
- 组合总和java代码有误
- error in slow-fast pointer in element removal
- 二叉树24:二叉搜索树的最小绝对差
- 二叉树19 332.重新安排行程 Java代码最后一个用例会超时
- 01背包问题的代码问题
- 为什么网站无搜索框了
- README文件,字符串章节的第三个题目链接错误
- 建议将之前代码随想录主页的,一二线城市的各互联网公司的汇总,放入拓展阅读的求职里面
- 字符串章节中有两个链接无效
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from leetcode-master.