forked from wotjd4305/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswe5215.java
More file actions
70 lines (51 loc) · 1.33 KB
/
swe5215.java
File metadata and controls
70 lines (51 loc) · 1.33 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
60
61
62
63
64
65
66
67
68
69
70
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class swe5215 {
static Boolean P_Arr[];
static ArrayList<Integer> AL = new ArrayList<>();
static int N ;
static int L ;
static int scores[];
static int cols[];
static int answer=0;
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
int T = sc.nextInt();
//Å×½ºÆ®ÄÉÀ̽º
for(int t=0; t<T; t++) {
//ÃʱâÈ
answer =0;
N = sc.nextInt();
L = sc.nextInt();
scores = new int[N];
cols = new int[N];
solution(N,L);
System.out.println("#"+ (t+1) + " " + answer);
}
}
public static void solution(int N, int L)
{
for(int i =0; i<N; i++)
{
scores[i] = sc.nextInt();
cols[i] = sc.nextInt();
}
dfs(0,0,0);
}
public static void dfs(int idx, int score, int col)
{
if(col > L)
return;
if(idx == N)
{
//System.out.println(score + " - " + col);
answer = Math.max(score, answer);
return;
}
int n_score = scores[idx];
int n_col = cols[idx];
dfs(idx+1, score, col);
dfs(idx+1, score+n_score, col+n_col);
}
}