내 코드
메모리 : 20180 KB
시간 : 200 ms
코드길이 : 1322 B
[내 코드]
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Solution {
static int[] arr;
static int N;
static int K;
static int result;
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
StringTokenizer st;
int T = Integer.parseInt(br.readLine());
for(int t = 1; t <= T; t++) {
sb.append('#').append(t).append(' ');
st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
K = Integer.parseInt(st.nextToken());
result = 0;
arr = new int[N];
boolean[] selected = new boolean[N];
st = new StringTokenizer(br.readLine());
for(int n = 0; n < N; n++) {
arr[n] = Integer.parseInt(st.nextToken());
}
for(int n = 0; n < N; n++) {
selected[n] = true;
search(n, 0, selected);
}
sb.append(result).append('\n');
}
System.out.print(sb);
}
public static void search(int index, int sum, boolean[] selected) {
sum += arr[index];
if(sum == K)
result++;
for(int i = index + 1; i < N; i++) {
if(!selected[i]) {
selected[i] = true;
search(i, sum, selected);
selected[i] = false;
}
}
return;
}
}
'SSAFY > SWEA' 카테고리의 다른 글
[SWEA] 3750 : Digit sum (0) | 2023.05.03 |
---|---|
[SWEA] 11315 : 오목판정 (0) | 2023.05.03 |
[SWEA] 4408 : 자기 방으로 돌아가기 (0) | 2023.05.03 |
[SWEA] 6485 : 삼성시의 버스 노선 (0) | 2023.05.02 |
[SWEA] 9229 : 한빈이와 spot Mart (0) | 2023.05.02 |