第一次意识到原来时间限制和空间限制也这么重要
def changeCoins(coins, n): if n < 0: return None dp, path = [0] * (n + 1), [0] * (n + 1) for i in range(1, n + 1): minNum = i for c in coins: if i >= c and minNum > dp[i - c] + 1: minNum, path[i] = dp[i - c] + 1, i - c dp[i] = minNum print(dp[-1]) if __name__ == '__main__': a,b=map(int,(input()).split()) coins = [] k=0 for i in range(a): k=k+1 coins.append(k) changeCoins(coins, b)
题目是硬币,牛家村货币
输入:第一行两个整数 m,n 表示货币最大面额和商品的价格
输出:支付的硬币的数量
eg:input: 6 7
output: 2
但是发现了问题,就是我没满足他的内存限制,真的不知道如何修改内存,功夫不到家
我的内存是这样,超了好多,我真垃圾