0
点赞
收藏
分享

微信扫一扫

Python:实现minimum coin change最小硬币找零算法(附完整源码)


Python:实现minimum coin change最小硬币找零算法

def dp_count(S, n):

if n < 0:
return 0
# table[i] represents the number of ways to get to amount i
table = [0] * (n + 1)

# There is exactly 1 way to get to zero(You pick no coins).
table[0] = 1


for coin_val in S:
for j in range(coin_val, n + 1):
table[j] += table[j - coin_val]

return table[n]


if __name__ == "__main__":
import doctest

doctest.testmod()


举报

相关推荐

0 条评论