Leetcode 518. Coin Change II

Problem

You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money.

Return the number of combinations that make up that amount. If that amount of money cannot be made up by any combination of the coins, return 0.

You may assume that you have an infinite number of each kind of coin.

The answer is guaranteed to fit into a signed 32-bit integer.

Algorithm

Dynamic Programming (DP). Complete knapsack problem, forward to sum the ways.

Code

python3 复制代码
class Solution:
    def change(self, amount: int, coins: List[int]) -> int:
        dp = [0] * (amount + 1)
        dp[0] = 1
        for coin in coins:
            for v in range(coin, amount+1):
                dp[v] += dp[v - coin]
        
        return dp[amount]
相关推荐
小欣加油7 分钟前
Leetcode31 下一个排列
数据结构·c++·算法·leetcode·职场和发展
_日拱一卒23 分钟前
LeetCode:39组合总和
java·算法·leetcode·职场和发展
无限进步_24 分钟前
【Linux】进程状态、僵尸与孤儿、进程调度
linux·运维·服务器·开发语言·数据结构·算法
郝学胜-神的一滴25 分钟前
力扣 662 :二叉树最大宽度
java·数据结构·c++·python·算法·leetcode·职场和发展
2301_7644413327 分钟前
基于Stackelberg博弈的分散式库存模型
python·算法·数学建模
qq 137401861136 分钟前
医用无菌屏障系统加速老化标准解读:ASTM F1980-2016 全解析
人工智能·算法·加速老化·包装测试·astm·医疗器械包装·无菌屏障系统
wayz1136 分钟前
Overlap:SLOPE(线性回归斜率)技术指标详解
算法·金融·数据分析·回归·线性回归·量化交易·特征工程
点云兔子37 分钟前
舱口检测:从点云到矩形定位的射线投影算法
opencv·算法·点云·舱口检测
小欣加油39 分钟前
leetcode169 多数元素
数据结构·c++·算法·leetcode·职场和发展
wayz111 小时前
Momentum:RVGI(相对活力指数)技术指标详解
算法·金融·数据分析·量化交易·特征工程