-
Notifications
You must be signed in to change notification settings - Fork 6
/
지한얼.java
65 lines (46 loc) · 1.18 KB
/
지한얼.java
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
60
61
62
63
64
import java.util.ArrayList;
import java.util.Scanner;
public class 지한얼 {
static ArrayList<int []> arr;
// static boolean[] visited;
static int L,n,answer;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int test=1; test<=t; test++) {
answer=0;
n=sc.nextInt();
L=sc.nextInt();
// visited = new boolean[n];
arr = new ArrayList<>();
for(int i=0; i<n;i++) { // 값넣기
arr.add(new int[]{sc.nextInt(),sc.nextInt()});
}
dfs(0, 0,0);
System.out.println("#"+test+" "+answer);
}
}
static void dfs(int total_T,int total_K,int depth) {
if(total_K>L) return ;
if (depth == n) {
if (total_T > answer) {
answer=total_T;
}
return;
}
int[] temp=arr.get(depth);
dfs(total_T+temp[0], total_K+temp[1], depth+1);
dfs(total_T, total_K, depth+1);
// for(int i=0; i<arr.size();i++) {
// if(!visited[i]) {
// visited[i]=true;
// int[] temp=arr.get(i);
// dfs(total_T+temp[0],total_K+temp[1],depth+1);
// visited[i]=false;
//
// if(answer<total_T) answer=total_T;
// }
// }
//
}
}