题解 | #找零#

找零

https://www.nowcoder.com/practice/944e5ca0ea88471fbfa73061ebe95728

n = int(input())
total = 1024-n
#枚举硬币 枚举背包 完全背包
ans = float('inf')
dp = [float('inf')] * (total+1) 
dp[0] = 0
for i in [1,4,16,64]:
    for j in range(i,total+1):
        dp[j] = min(dp[j],dp[j-i]+1)#要用到当前的迭代结果
print(dp[total])
#建议牛客在专项练习上进行改进#
全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务