mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
Update 背包问题理论基础完全背包.md
添加 python3 版本代码
This commit is contained in:
@ -33,7 +33,7 @@
|
||||
示例 3:
|
||||
输入: amount = 10, coins = [10]
|
||||
输出: 1
|
||||
|
||||
|
||||
注意,你可以假设:
|
||||
|
||||
* 0 <= amount (总金额) <= 5000
|
||||
@ -207,6 +207,21 @@ class Solution {
|
||||
|
||||
Python:
|
||||
|
||||
```python3
|
||||
class Solution:
|
||||
def change(self, amount: int, coins: List[int]) -> int:
|
||||
dp = [0]*(amount + 1)
|
||||
dp[0] = 1
|
||||
# 遍历物品
|
||||
for i in range(len(coins)):
|
||||
# 遍历背包
|
||||
for j in range(coins[i], amount + 1):
|
||||
dp[j] += dp[j - coins[i]]
|
||||
return dp[amount]
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
Go:
|
||||
|
||||
|
Reference in New Issue
Block a user