当前位置:网站首页>Leetcode: countless denominations of coins get the option of amount (DP)
Leetcode: countless denominations of coins get the option of amount (DP)
2022-04-21 13:16:00 【Review of the white speed Dragon King】

analysis
In order First traversal amount And then iterate through each coin That's all right.
If calculated by combination Suppose you choose coins[i], that j From coins[i] To amount Add up dp[j]
code comparison
class Solution:
def change(self, amount: int, coins: List[int]) -> int:
''' # This is calculated in order dp = [0] * (amount + 1) dp[0] = 1 # There's always a way to choose nothing for i in range(1, amount + 1): for coin in coins: if i >= coin: dp[i] += dp[i - coin] return dp[-1] '''
# This is calculated by combination
dp = [0] * (amount + 1)
dp[0] = 1 # There's always a way to choose nothing
n = len(coins)
# Chose one coins[i]
# Always choose coins[i]
for i in range(n):
for j in range(coins[i], amount + 1):
dp[j] += dp[j - coins[i]]
return dp[-1]
summary
Countless silver coins , Multiple denominations
Fixed total
The distinction between permutation and combination
版权声明
本文为[Review of the white speed Dragon King]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211313419487.html
边栏推荐
- [C#]给地球来点光
- 滑动窗口系列-寻找最小覆盖字串
- L2-013 红色警报 (25 分)
- The course of qiniu business school allows Xiaobai to open an account and make new debts. Is it safe?
- Select elements from Revit (issue 5)
- 乡村vlog收割8000w+播放,又一个流量天花板?
- Algorithem_ Merge Two Binary Trees
- Algorithem_Populating Next Right Pointers in Each Node
- C language nesting exercise
- 万字干货!帮你深度掌握设计中的「光影」知识点 (下)
猜你喜欢

How a person makes self media videos, and the operation skills in the field of agriculture, rural areas and farmers

36 day assault Tencent finally took the offer! Redis, high concurrency

乡村vlog收割8000w+播放,又一个流量天花板?

Fibonacci sequence

QFileInfo文件和文件夹操作

安装和配置Canal

Go language file operation

leetcode:513. 找树左下角的值【简单bfs找每层第一个】

Baidu map development custom information window openinfowindow style

百度地图开发自定义信息窗口openInfoWindow样式
随机推荐
农产品期货品种有哪些呢?
Wireless network protocol terms
Revit二次开发之——lookup的使用方法(第七期)
科技巨头竞相入场,谁能成为元宇宙“头号玩家”?
leetcode:824. 山羊拉丁文【简单字符串操纵】
OJ daily practice - output new array in reverse order
twenty million two hundred and ten thousand eight hundred and twelve
Elements of network
S: Unit gain compensation
[digital signal processing] correlation coefficient (concept analysis of correlation coefficient | signal energy constant | conjugate sequence | correlation of sequence at the same time)
一文读懂Faster RCNN
上周国外互联网产品新闻简编 - Angel
Build a service registration and Discovery Center
The course of qiniu business school allows Xiaobai to open an account and make new debts. Is it safe?
Ugui -- button component
leetcode:无数个面额的硬币得到amount的选法(dp)
S TYLE N E RF: A S TYLE - BASED 3D-A WARE G ENERA - TOR FOR H IGH - RESOLUTION I MAGE S YNTHESIS
Revit secondary development - multi pipe linear annotation (phase 18)
Revit secondary development - creating walls (2) (phase 11)
[digital signal processing] linear constant coefficient difference equation (use matlab to solve the example of "linear constant coefficient difference equation" | a vector analysis | B vector analysi