def solve_coin_change_dp(coins, value): """A dynamic solution to the coin change problem with optimal solution""" solution = [None for x in range(value + 1)] solution[0] = [] for i in range(1, value + 1): for coin in coins: if coin > i: continue elif not solution[i] or len(solution[i - coin]) + 1 < len( solution[i]): if solution[i - coin] != None: solution[i] = solution[i - coin][:] solution[i].append(coin) if solution[-1] != None: #print '%d coins: %s' % (len(solution[-1]), solution[-1]) + "for " + str(value) return solution[-1] 我的DP 代码,请看看