BOJ 1182번 부분수열의 합
14 Mar 2020 | Algorithm
import java.util.Scanner;
public class BOJ_1182 {
static int[] num;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int s = sc.nextInt();
num = new int[n];
for (int i = 0; i < n; i++) {
num[i] = sc.nextInt();
}
int answer = 0;
for (int i = 1; i < (1 << n); i++) {
int sum = 0;
for (int k = 0; k < n; k++) {
if ((i & (1 << k)) != 0)
sum += num[k];
}
if(sum == s)
answer++;
}
System.out.println(answer);
}
}