题解 | #称砝码#
称砝码
http://www.nowcoder.com/practice/f9a4c19050fc477e9e27eb75f3bfd49c
n_class = int(input())
weight_obj = [int(i) for i in input().strip().split(' ')]
num_obj = [int(i) for i in input().strip().split(' ')]
weight_set = set()
weight_set.add(0)
obj_weight = []
for i, num in enumerate(num_obj, 0):# 将所有的砝码按个展开到列表
for j in range(num):
obj_weight.append(weight_obj[i])
for i in obj_weight:# 对于已经存在的重量
# for one_weight in weight_set.copy():# 要是可以放在另一边,好像可以称更多重量
# if one_weight - i not in weight_set and one_weight - i > 0:
# weight_set.add(one_weight - i)
for one_weight in weight_set.copy():
if one_weight + i not in weight_set and one_weight + i > 0:
weight_set.add(one_weight + i)
print(len(weight_set))