Skip to content

Commit 15e3377

Browse files
committed
Update 0518.零钱兑换II.md 对dp[0]=1的补充解释
1 parent f2e525d commit 15e3377

File tree

3 files changed

+3
-0
lines changed

3 files changed

+3
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

problems/.DS_Store

6 KB
Binary file not shown.

problems/0518.零钱兑换II.md

+3
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ dp[j] 就是所有的dp[j - coins[i]](考虑coins[i]的情况)相加。
9595

9696
下标非0的dp[j]初始化为0,这样累计加dp[j - coins[i]]的时候才不会影响真正的dp[j]
9797

98+
dp[0]=1还说明了一种情况:如果正好选了coins[i]后,也就是j-coins[i] == 0的情况表示这个硬币刚好能选,此时dp[0]为1表示只选coins[i]存在这样的一种选法。
99+
98100
4. 确定遍历顺序
99101

100102
本题中我们是外层for循环遍历物品(钱币),内层for遍历背包(金钱总额),还是外层for遍历背包(金钱总额),内层for循环遍历物品(钱币)呢?
@@ -316,3 +318,4 @@ object Solution {
316318
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
317319
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
318320
</a>
321+

0 commit comments

Comments
 (0)