题解 | #称砝码#
称砝码
https://www.nowcoder.com/practice/f9a4c19050fc477e9e27eb75f3bfd49c
n = int(input()) m, x = [0]*n, [0]*n # # 防止后续去重算出总重量 # m_max = 0 m = list(map(int, input().split())) x = list(map(int, input().split())) # for i in range(n): # m_max += m[i]*x[i] ct = 0 # 标志0-max 是否有取值 # m_flag = [0 for i in range(0, m_max+1)] # m_flag[0] = 1 sum_m ={0,} for i in range(n): # 已有质量加上新的质量 ,从后向前遍历 for mm in list(sum_m): for j in range(1, x[i]+1): sum_m.add(mm+m[i]*j) ct = len(sum_m) print(ct)