Skip to content

Commit 308fb57

Browse files
committed
[Gold V] Title: 캠프 준비, Time: 116 ms, Memory: 14596 KB -BaekjoonHub
1 parent 4b127fe commit 308fb57

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# [Gold V] 캠프 준비 - 16938
2+
3+
[문제 링크](https://www.acmicpc.net/problem/16938)
4+
5+
### 성능 요약
6+
7+
메모리: 14596 KB, 시간: 116 ms
8+
9+
### 분류
10+
11+
백트래킹, 비트마스킹, 브루트포스 알고리즘
12+
13+
### 제출 일자
14+
15+
2025년 3월 24일 11:19:34
16+
17+
### 문제 설명
18+
19+
<p>알고리즘 캠프를 열려면 많은 준비가 필요하다. 그 중 가장 중요한 것은 문제이다. 오늘은 백준이를 도와 알고리즘 캠프에 사용할 문제를 고르려고 한다.</p>
20+
21+
<p>백준이는 문제를 N개 가지고 있고, 모든 문제의 난이도를 정수로 수치화했다. i번째 문제의 난이도는 A<sub>i</sub>이다.</p>
22+
23+
<p>캠프에 사용할 문제는 두 문제 이상이어야 한다. 문제가 너무 어려우면 학생들이 멘붕에 빠지고, 문제가 너무 쉬우면 학생들이 실망에 빠지게 된다. 따라서, 문제 난이도의 합은 L보다 크거나 같고, R보다 작거나 같아야 한다. 또, 다양한 문제를 경험해보기 위해 가장 어려운 문제와 가장 쉬운 문제의 난이도 차이는 X보다 크거나 같아야 한다.</p>
24+
25+
<p>캠프에 사용할 문제를 고르는 방법의 수를 구해보자.</p>
26+
27+
### 입력
28+
29+
<p>첫째 줄에 N, L, R, X가 주어진다.</p>
30+
31+
<p>둘째 줄에는 문제의 난이도 A<sub>1</sub>, A<sub>2</sub>, ..., A<sub>N</sub>이 주어진다.</p>
32+
33+
### 출력
34+
35+
<p>캠프에 사용할 문제를 고르는 방법의 수를 출력한다.</p>
36+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main {
5+
static int N,L,R,X,arr[];
6+
static int answer = 0;
7+
public static void main(String[] args) throws IOException {
8+
9+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
11+
StringTokenizer st = new StringTokenizer(br.readLine());
12+
13+
N = Integer.parseInt(st.nextToken());
14+
L = Integer.parseInt(st.nextToken());
15+
R = Integer.parseInt(st.nextToken());
16+
X = Integer.parseInt(st.nextToken());
17+
18+
arr = new int[N];
19+
st = new StringTokenizer(br.readLine());
20+
for(int i =0; i<N; i++) {
21+
arr[i] = Integer.parseInt(st.nextToken());
22+
}
23+
24+
dfs(0,0,0,0,0);
25+
System.out.println(answer);
26+
}
27+
28+
static void dfs(int index, int value, int problemCount, int minValue, int maxValue) {
29+
if(index == N) {
30+
if(problemCount >= 2 && value >= L && value <= R && maxValue - minValue >= X) {
31+
answer++;
32+
}
33+
return;
34+
}
35+
36+
int newMin = (problemCount == 0) ? arr[index] : Math.min(minValue, arr[index]);
37+
int newMax = (problemCount == 0) ? arr[index] : Math.max(maxValue, arr[index]);
38+
39+
dfs(index + 1, value + arr[index], problemCount + 1, newMin, newMax);
40+
41+
dfs(index + 1, value, problemCount, minValue, maxValue);
42+
}
43+
}

0 commit comments

Comments
 (0)