程序的其他版本:
def change(C, V, res=None): res = [] if res is None else res if len(V) == 0: return len(res), res maxx = max(V) V.remove(maxx) ans = C//maxx if ans == 0 and maxx < C : res += [maxx] * ans return len(res), res else: res += [maxx] * ans return change(C % maxx, V, res)print change(48,[1, 5, 10, 25, 50])print change(30,[25, 10, 2, 3, 1])
输出:
(6, [25, 10, 10, 1, 1, 1])(3, [25, 3, 2])
PS:如果您愿意,我会添加一个说明。



