贪心算法: Value = (10,5,2,1) def GreedyChange(target:int): ret = {} if target Value[0]: return False for val in Value: shang,yushu = divmod(target,val) if yushu == 0: ret[str(val)] = shang print(ret) return else: ret[str(val)] = shang
贪心算法:
Value = (10,5,2,1)def GreedyChange(target:int):
ret = {}
if target < Value[0]:
return False
for val in Value:
shang,yushu = divmod(target,val)
if yushu == 0:
ret[str(val)] = shang
print(ret)
return
else:
ret[str(val)] = shang
target = yushu
GreedyChange(219)