题解 | #称砝码#
称砝码
https://www.nowcoder.com/practice/f9a4c19050fc477e9e27eb75f3bfd49c
import java.util.*; public class Main { public static void main(String[] args) { Scanner fzhinput = new Scanner(System.in); int fmzls = fzhinput.nextInt(); List<Integer> fmzl = new ArrayList<>() ; List<Integer> fmsl = new ArrayList<>() ; Set<Integer> zlsz = new HashSet<>(); if (fmzls >= 1 || fmzls <= 10) { for (int i = 0; i < fmzls; i++) { int sr = fzhinput.nextInt(); if (sr >= 1 && sr <= 2000) { fmzl.add(sr); } } for (int i = 0; i < fmzls; i++) { int sr1 = fzhinput.nextInt(); if (sr1 >= 1 && sr1 <= 10) { fmsl.add(sr1); } } } zlsz.add(0); for (int i = 0; i < fmzls; i++) { Set<Integer> dqzl = new HashSet<>(zlsz); for (int w : dqzl) { for (int j = 1; j <=fmsl.get(i); j++) { int zl = w + fmzl.get(i) * j; zlsz.add(zl); } } } System.out.print(zlsz.size()); } }