forked from wotjd4305/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswe3282.java
More file actions
59 lines (51 loc) · 1.52 KB
/
swe3282.java
File metadata and controls
59 lines (51 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import java.util.Scanner;
public class swe3282 {
static Scanner sc = new Scanner(System.in);
static int answer = 0;
static int N;//물건갯수
static int K;//한도
static int[][] Arr;
static boolean visit[];
public static void main(String[] args) {
solution();
}
public static void solution() {
int t = sc.nextInt();
for (int T = 1; T <= t; T++) {
answer = 0;
N = sc.nextInt();
K = sc.nextInt();
visit = new boolean[N];
Arr = new int[N][2];
//입력
//0 부피, 1 가치
for (int i = 0; i < N; i++) {
Arr[i][0] = sc.nextInt();
Arr[i][1] = sc.nextInt();
}
//처리
//N은 물건갯수, K는 한도
for (int i = 0; i < N; i++) {
visit[i] = true;
dfs(Arr[i][0], Arr[i][1]);
visit[i] = false;
}
System.out.println("#" + T + " " + answer);
}
}
public static void dfs(int volum_total, int value_total) {
//부피넘으면 빠져나가기
if (volum_total > K)
return;
if(value_total > answer){
answer = Math.max(answer, value_total);
}
for (int i = 0; i < N; i++) {
if (!visit[i]) {
visit[i] = true;
dfs(volum_total + Arr[i][0], value_total + Arr[i][1]);
visit[i] = false;
}
}
}
}