题解 | #称砝码#
称砝码
https://www.nowcoder.com/practice/f9a4c19050fc477e9e27eb75f3bfd49c
num = input(''); wei_num = []; for ii = 1 : 2 line = input('', 's'); lines = strsplit(line,' '); for jj = 1 : num d11 = lines{jj}; wei_num(ii,jj) = str2num(d11); end end num_now = []; for jj = 1 : size(wei_num,2) num_now =[num_now;repmat(wei_num(1,jj),wei_num(2,jj),1)]; end out_end = [0]; %%% 重复的类型 for ii = 1 : length(num_now) out_now = out_end + num_now(ii); out_end = [out_end out_now]; out_end = unique(out_end); end printf("%d\n",length(out_end));