第二题:暴力,AC,JAVA
import java.util.Scanner;
public class Main2 {
public static void main(String[] args){
Scanner sc =new Scanner(System.in);
int n = sc.nextInt();
int[] list = new int[n];
for (int i = 0; i < n; i++) list[i] = sc.nextInt();
int tar = sc.nextInt();
System.out.println(count(list,0,0,tar, 0));
}
public static boolean count(int[] list, int po, int sum, int tar, int n){
if (po >= list.length) return false;
if ((n > 0 && sum == tar) || sum+list[po] == tar) return true;
return count(list, po + 1, sum , tar, n) ||
count(list, po + 1, sum + list[po], tar, n+1);
}
}