SWEA 5215 햄버거 다이어트

1 개요[ | ]

SWEA 5215 햄버거 다이어트
SW Expert 아카데미
# 문제 풀이

틀:SWEA 난이도 3-2

2 C++[ | ]

3 Java[ | ]

import java.util.*;
public class Solution {
    static int N, L, maxScore;
    static int[] scores, cals;
    public static void solve(int score, int cal, int k) {
        if(k+1 > N) {
            if( cal <= L && score > maxScore ) maxScore = score;
            return;
        }
        solve(score, cal, k+1);
        solve(score+scores[k], cal+cals[k], k+1);
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
 
        for(int tc=1; tc<=T; tc++) {
            N = sc.nextInt();
            L = sc.nextInt();
            maxScore = 0;
            scores = new int[N];
            cals = new int[N];
            for(int i=0; i<N; i++) {
                scores[i] = sc.nextInt();
                cals[i] = sc.nextInt();
            }
            solve(0, 0, 0);
            System.out.format("#%d %d\n", tc, maxScore);
        }
        sc.close();
    }
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}