SWEA_D3_5215
π [D3_5215] νλ²κ±° λ€μ΄μ΄νΈ
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Solution {
static int N, L;
static int cal_sum, score_sum;
static int[] cal, score;
static int res;
static boolean[] isChecked;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
int TC = Integer.parseInt(st.nextToken());
for (int T = 1; T <= TC; T++) {
st = new StringTokenizer(br.readLine(), " ");
N = Integer.parseInt(st.nextToken());
L = Integer.parseInt(st.nextToken());
score = new int[N];
cal = new int[N];
isChecked = new boolean[N];
// Test Case κ° μ
λ ₯
for (int TT = 0; TT < N; TT++) {
st = new StringTokenizer(br.readLine(), " ");
int c = Integer.parseInt(st.nextToken());
int s = Integer.parseInt(st.nextToken());
score[TT] = c;
cal[TT] = s;
}
// λΆλΆμ§ν© κ³μ° go()
res = 0;
go(0);
System.out.println("#" + T + " " + res);
}
}
public static void go(int idx) {
if (idx == N) {
cal_sum = 0;
score_sum = 0;
for (int i = 0; i < N; i++) {
if (isChecked[i]) {
cal_sum += cal[i];
score_sum += score[i];
}
}
if (cal_sum < L && score_sum > res) {
res = score_sum;
}
return;
}
isChecked[idx] = true;
go(idx + 1);
isChecked[idx] = false;
go(idx + 1);
}
}
π€ λμ μκ°
λΆλΆ μ§ν©μ ν©μΌλ‘ ν μ μμλ€.
score μ cal μ ν©λ€μ ꡬν΄μ cal ν©μ΄ Lμ΄νμΈ κ²μμ μ΅λ scoreμ ν©μ ꡬν΄λ΄λ©΄ λλ€.