题解 | #称砝码#

称砝码

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

n = int(input())

weights = list(map(int, input().split()))

nums = list(map(int ,input().split()))

res = {0,}

all = []

for i in range(n):
    for j in range(nums[i]):
        all.append(weights[i])

for i in all:
    for j in list(res):  # 在迭代res不能改变res的大小,加list()转换成临时的list则可以改变原来的res
        res.add(i+j)

print(len(res))


全部评论

相关推荐

06-11 17:39
门头沟学院 Java
小呆呆的大鼻涕:卧槽,用户彻底怒了
点赞 评论 收藏
分享
在喝茶的牛油很喜欢吃...:今天oc了
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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