mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-06 07:06:42 +08:00
Update 0518.零钱兑换II.md 对dp[0]=1的补充解释
This commit is contained in:
BIN
problems/.DS_Store
vendored
Normal file
BIN
problems/.DS_Store
vendored
Normal file
Binary file not shown.
@ -95,6 +95,8 @@ dp[j] 就是所有的dp[j - coins[i]](考虑coins[i]的情况)相加。
|
||||
|
||||
下标非0的dp[j]初始化为0,这样累计加dp[j - coins[i]]的时候才不会影响真正的dp[j]
|
||||
|
||||
dp[0]=1还说明了一种情况:如果正好选了coins[i]后,也就是j-coins[i] == 0的情况表示这个硬币刚好能选,此时dp[0]为1表示只选coins[i]存在这样的一种选法。
|
||||
|
||||
4. 确定遍历顺序
|
||||
|
||||
本题中我们是外层for循环遍历物品(钱币),内层for遍历背包(金钱总额),还是外层for遍历背包(金钱总额),内层for循环遍历物品(钱币)呢?
|
||||
@ -316,3 +318,4 @@ object Solution {
|
||||
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
||||
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
|
||||
</a>
|
||||
|
||||
|
Reference in New Issue
Block a user