采用DFS:
import java.util.*;
public class Main{
static int n;
static int[] arr;
static int k;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
arr = new int[n];
k = sc.nextInt();
for(int i = 0;i < n;i++) {
arr[i] = sc.nextInt();
}
if(dfs(0,0)) {
System.out.println("YES");
}
else {
System.out.println("NO");
}
sc.close();
}
private static boolean dfs(int i,int sum) {
if(i == n) {
return sum == k;
}
if(dfs(i+1,sum)) {
return true;
}
return dfs(i+1,sum+arr[i]);
}
}