目录
学习目标
学习内容
完全背包
518. 零钱兑换 II
377. 组合总和 Ⅳ
学习目标
- 完全背包
- 518. 零钱兑换 II
- 377. 组合总和 Ⅳ
学习内容
完全背包
problems/背包问题理论基础完全背包.md · programmercarl/leetcode-master(代码随想录出品) - Gitee.comhttps://gitee.com/programmercarl/leetcode-master/blob/master/problems/%E8%83%8C%E5%8C%85%E9%97%AE%E9%A2%98%E7%90%86%E8%AE%BA%E5%9F%BA%E7%A1%80%E5%AE%8C%E5%85%A8%E8%83%8C%E5%8C%85.md
518. 零钱兑换 II
518. 零钱兑换 II - 力扣(LeetCode)https://leetcode.cn/problems/coin-change-ii/
class Solution:
def change(self, amount: int, coins: List[int]) -> int:
n = len(coins)
dp = [0]*(amount+1)
dp[0] = 1
for i in range(n):
for j in range(coins[i],amount+1):
dp[j] += dp[j-coins[i]]
#print(dp)
return dp[amount]
377. 组合总和 Ⅳ
377. 组合总和 Ⅳ - 力扣(LeetCode)https://leetcode.cn/problems/combination-sum-iv/
class Solution:
def combinationSum4(self, nums: List[int], target: int) -> int:
n = len(nums)
dp = [0]*(target+1)
dp[0] = 1
for j in range(1,target+1):
for num in nums:
if j>=num:
dp[j]+=dp[j-num]
return dp[target]