Skip to content

Commit 7e250ec

Browse files
authored
[20250722] BOJ / G5 / 캠프 준비 / 김수연
1 parent aecd775 commit 7e250ec

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
```java
2+
import java.util.*;
3+
import java.io.*;
4+
5+
public class boj16938 {
6+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
static StringTokenizer st;
8+
static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());}
9+
static int nextInt() {return Integer.parseInt(st.nextToken());}
10+
11+
static int N, L, R, X;
12+
static int[] arr;
13+
static int tmp_cnt,tmp_min,tmp_answer;
14+
public static void main(String[] args) throws Exception {
15+
nextLine();
16+
N = nextInt();
17+
L = nextInt();
18+
R = nextInt();
19+
X = nextInt();
20+
arr = new int[N];
21+
nextLine();
22+
for (int i = 0; i < N; i++) arr[i] = nextInt();
23+
Arrays.sort(arr);
24+
25+
int answer = 0;
26+
for(int i = 0; i < N-1; i++) {
27+
tmp_cnt = N-i;
28+
tmp_min = arr[i];
29+
tmp_answer = 0;
30+
comb(i+1,1,1,arr[i],arr[i]);
31+
answer += tmp_answer;
32+
}
33+
System.out.print(answer);
34+
}
35+
36+
static void comb(int idx, int cnt,int add_cnt,int max,int tot) {
37+
if(cnt == tmp_cnt) {
38+
if(add_cnt > 1 && (max-tmp_min >= X) && (tot >= L && tot <= R)) tmp_answer++;
39+
return;
40+
}
41+
42+
for(int i = idx; i < N; i++) {
43+
comb(i+1,cnt+1,add_cnt,max,tot);
44+
comb(i+1,cnt+1,add_cnt+1,arr[i],tot+arr[i]);
45+
}
46+
}
47+
}
48+
```

0 commit comments

Comments
 (0)