用python语言实现“连续邮资”问题的回溯算法,怎么求?
求解答…
1条回答 默认 最新
关注
Max = 4 Prices = [0,1,3,11,15,32] # 单价列表 def Traceback(count): global tmp,flag,Result if count==Max: if tmp == Result+1: flag = True return for i in range(len(Prices)): tmp += Prices[i] if tmp <= Result+1: Traceback(count+1) tmp -= Prices[i] Result = 0 tmp = 0 while True: flag = False Traceback(0) if flag: Result += 1 else: break print(Result)
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用 1