题解 | #称砝码#

称砝码

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

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

s = {0}

for i in range(n):
    for _ in range(counts[i]):
        for w in list(s):   # "freeze" the elements to iterate over regardless of adds.
            s.add(weights[i] + w)
print(len(s))

Claude辅助作品,一开始想的是用dfs之类的...

全部评论

相关推荐

点赞 评论 收藏
分享
01-02 21:17
已编辑
西安理工大学 后端
程序员小白条:项目不太重要,你的优势的算法竞赛,然后多背相关的八股文,项目可以不作为重点考虑,面试可能就简单带过项目就行了,你可以直接写简历,背项目相关的八股文就行,也不用自己做,时间紧张的情况下,性价比最高
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务