题解 | #称砝码#
称砝码
https://www.nowcoder.com/practice/f9a4c19050fc477e9e27eb75f3bfd49c
n_weights = int(input())
weights = [int(w) for w in input().split()]
nums = [int(i) for i in input().split()]
# credits to wfj
def count_different_weights(n, weight_lst, count_lst):
exist_weights = {0}
for w, c in zip(weight_lst, count_lst):
need_try_to_add_one = exist_weights
for i in range(c):
need_try_to_add_more = []
for wi in need_try_to_add_one:
wi += w
if wi not in exist_weights:
need_try_to_add_more.append(wi)
need_try_to_add_one = need_try_to_add_more
exist_weights.update(need_try_to_add_one)
return len(exist_weights)
result = count_different_weights(n_weights, weights, nums)
print(result)
算法学习分析与整理 文章被收录于专栏
个人学习算法的文档整理与思考,举一反三,相爱相杀。
SHEIN希音公司福利 284人发布
