题解 | #称砝码#

称砝码

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))
全部评论

相关推荐

10-30 10:16
南京大学 Java
龚至诚:给南大✌️跪了
点赞 评论 收藏
分享
shtdbb_:还不错,没有让你做了笔试再挂你
点赞 评论 收藏
分享
评论
1
1
分享
牛客网
牛客企业服务