Notice
Recent Posts
Recent Comments
Link
«   2025/04   »
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
Tags
more
Archives
Today
Total
관리 메뉴

걸음마부터 달리기

SWEA 햄버거 본문

카테고리 없음

SWEA 햄버거

성추 2025. 4. 11. 22:37
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);
    }
}

조합문제다.