MCPcopy Index your code
hub / github.com/Jack-Lee-Hiter/AlgorithmsByPython / coinRow

Function coinRow

Dynamic Programming.py:19–24  ·  view source on GitHub ↗
(coinrow)

Source from the content-addressed store, hash-verified

17# 输入数组C[1..n]保存n个硬币的面值
18# 输出可选硬币的最大金额
19def coinRow(coinrow):
20 alist = [0]*(len(coinrow)+1)
21 alist[1] = coinrow[0]
22 for i in range(2, len(coinrow)+1):
23 alist[i] = max(coinrow[i-1]+alist[i-2], alist[i-1])
24 return alist.pop()
25
26print(coinRow([5, 1, 2, 10, 6, 2]))
27

Callers 1

Calls 1

popMethod · 0.45

Tested by

no test coverage detected