재귀로 부분 집합 구현
import java.util.Scanner;
class Solution {
static int N, K, countK;
static int[] arr;
public static void main(String args[]) throws Exception {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for(int test_case = 1; test_case <= T; test_case++) {
N = sc.nextInt();
K = sc.nextInt();
arr = new int[N];
for(int i = 0; i < N; i++) {
arr[i] = sc.nextInt();
}
countK = 0;
powerset(0, 0);
System.out.println("#" + test_case + " " + countK);
}
}
static void powerset(int idx, int sum) {
if(idx == N) {
if(sum == K) countK++;
return;
} else {
powerset(idx + 1, sum);
sum += arr[idx];
powerset(idx + 1, sum);
}
}
}