解题思路:
注意事项:
参考代码:
def create_huffman(nums): cost = 0 while len(nums) > 1: pa = nums.pop(nums.index(min(nums))) pb = nums.pop(nums.index(min(nums))) cost += (pa + pb) nums.append(pa+pb) return cost N = int(input()) num_list = list(map(int, input().split())) costs = create_huffman(num_list[:N]) print(costs)
0.0分
0 人评分