public static void main(String[] args){ Scanner scan=new Scanner(System.in); int[] arr=new int[scan.nextInt()]; scan.nextLine(); for(int i=0;i<arr.length;i++) arr[i]=scan.nextInt(); int[] solution=new int[scan.nextInt()]; scan.nextLine(); for(int i=0;i<solution.length;i++){ solution[i]=scan.nextInt(); scan.nextLine(); } boolean[] res=new boolean[solution.length]; Set<Integer> set=new HashSet(); set.add(0); for(int i=0;i<arr.length;i++){ Iterator<Integer> iterator=set.iterator(); Set<Integer> tmp=new HashSet(); while(iterator.hasNext()) tmp.add(iterator.next()+arr[i]); set.addAll(tmp); } for(int i=0;i<solution.length;i++){ if(solution[i]>10000){ System.out.println("NO"); continue; } Iterator<Integer> iterator=set.iterator(); boolean flag=false; while(iterator.hasNext()){ int val=iterator.next(); if(set.contains(val-solution[i])){ flag=true; break; } } System.out.println(flag?"YES":"NO"); } }
全部评论
(1) 回帖