题解 | 称砝码

称砝码

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

n = int(input())
weights = [int(i) for i in input().split()]
nums = [int(i) for i in input().split()]
set1 = set()
set1.add(0)
for i in range(n):
    for num in range(1,nums[i]+1):
        tempset = set()
        for j in set1:
            tempset.add(j+weights[i])
        set1 |= tempset
print(len(set1))

全部评论

相关推荐

05-24 14:12
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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