题解 | #称砝码#
称砝码
https://www.nowcoder.com/practice/f9a4c19050fc477e9e27eb75f3bfd49c
import sys num = int(input()) num_arr = list(map(int, input().split())) weight_arr = list(map(int, input().split())) info = list(zip(num_arr, weight_arr)) # print(num, info) def handle(data): """用到递归方法""" weight_arr = list([0,]) for d in range(data[0][1]+1): one_weight = data[0][0]*d if one_weight not in weight_arr: weight_arr.append(one_weight) data.pop(0) if len(data): tmp = handle(data) arr_copy = weight_arr.copy() for i in arr_copy: for t in tmp: summary = i + t weight_arr.append(summary) weight_arr = list(set(weight_arr)) return weight_arr if __name__ == '__main__': result = handle(info) print(len(result))