题解 | #称砝码#

称砝码

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

相关推荐

01-19 15:14
已编辑
延安大学 C++
累死的一条狗:我说白了这种玩意你直接点举报就完事了在给他挂出来
找工作以来,你最看不惯_...
点赞 评论 收藏
分享
02-06 16:33
门头沟学院 Java
Phoenix_Re...:很少最多一两个,大多数保研或者摆烂等着考研
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务