题解 | #称砝码#
称砝码
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之类的...