题解 | #称砝码#
称砝码
https://www.nowcoder.com/practice/f9a4c19050fc477e9e27eb75f3bfd49c
n = int(input()) m = list(map(int,input().split())) x = list(map(int,input().split())) mx = []#只放一个砝码时有多少种情况 for i in range(n): mx.extend([m[i]]*x[i]) weights = {0}#每次只加一个砝码上去记录下此时的重量 for i in mx: #每次放入一个i和重量记录表各个值相加得到新的砝码组合重量,集合自动去重 weights = weights.union({i+j for j in weights}) print(len(weights))