题解 | #称砝码#
称砝码
https://www.nowcoder.com/practice/f9a4c19050fc477e9e27eb75f3bfd49c
Inspired by the top c++ answer.
Use set to get the results
n = int(input()) m = list(map(int, input().split())) x = list(map(int, input().split())) weights = [] res = set() res.add(0) for i in range(n): weights += [m[i]] * x[i] for elm in weights: for j in list(res): res.add(elm+j) print(len(res))