题解 | #称砝码#

称砝码

http://www.nowcoder.com/practice/f9a4c19050fc477e9e27eb75f3bfd49c

集合

# 输入
n = int(input())
weight = list(map(int,input().split()))
weightNum = list(map(int,input().split()))
# 整合
arr = []
for i in range(n):
    for j in range(weightNum[i]):
        arr.append(weight[i])
# 所有组合情况
res = {0}
for i in arr:
    for j in list(res):
        # 集合去重
        res.add(i+j)
print(len(res))
        
全部评论

相关推荐

昨天 18:09
门头沟学院 Java
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-17 14:06
点赞 评论 收藏
分享
头顶尖尖的程序员:我也是面了三四次才放平心态的。准备好自我介绍,不一定要背熟,可以记事本写下来读。全程控制语速,所有问题都先思考几秒,不要急着答,不要打断面试官说话。
点赞 评论 收藏
分享
评论
2
1
分享

创作者周榜

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