题解 | #称砝码#
称砝码
https://www.nowcoder.com/practice/f9a4c19050fc477e9e27eb75f3bfd49c
import sys
while 1:
try:
n = int(input()) # 砝码的种数
weight = list(map(int,input().split())) # 砝码的重量
number = list(map(int,input().split())) # 每种砝码对应的数量
except:
break
else:
amount = []
c = {0,}
for i in range(n):
for j in range(number[i]):
amount.append(weight[i])
for i in amount:
for j in list(c): #循环时set转换回list
c.add(j+i)
#print(c)
print(len(c))

查看4道真题和解析