题解 | #称砝码# set.add()

称砝码

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

n=int(input())
m=list(map(int,input().split()))
x=list(map(int,input().split()))

m1=[]
for i in range(n):
    for j in range(x[i]):
        m1.append(m[i])
#print(m1)

weight=0
weight_rec={0} # 集合,自动去重,记录重量,包括0
for i in m1:
    for j in list(weight_rec):
        weight_rec.add(i+j)


print(len(weight_rec))


每增加一个重量的砝码,前期的重量组合都要更新(新砝码与每个组合重量相加),用集合去重。

全部评论

相关推荐

真的很糟糕:不一定是你的问题,当然你也可以做的更好一些,继续投相信自己一定会有的
点赞 评论 收藏
分享
怼怼高:我想问一下其他软件都是自己学的吗,我们学校只学了ps ai诶
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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