걸음마부터 달리기
SWEA 햄버거 본문
import java.util.*;
import java.io.*;
class Main {
static int T;
static int N;
static int L;
static int max;
static int[] score;
static int[] calories;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
T = Integer.parseInt(br.readLine());
for (int l = 0; l < T; l++) {
String[] s = br.readLine().split(" ");
N=Integer.parseInt(s[0]);
L=Integer.parseInt(s[1]);
max= Integer.MIN_VALUE;
score = new int[N];
calories = new int[N];
for(int i=0;i<N;i++) {
s= br.readLine().split(" ");
calories[i]=Integer.parseInt(s[1]);
score[i]=Integer.parseInt(s[0]);
}
combination(0,0,0);
System.out.printf("#%d %d\n",l+1,max);
}
}
public static void combination(int depth, int k , int s){
if(k>L){
return;
}
if(depth==N){
if(max<s){
max=s;
}
return;
}
combination(depth+1,k+calories[depth] , s+score[depth]);
combination(depth+1,k , s);
}
}
조합문제다.