슈콩

[프로그래머스] Lv.2 피로도 본문

Algorithms/Programmers

[프로그래머스] Lv.2 피로도

shukong 2025. 10. 15. 14:15

 

 

[문제]

https://school.programmers.co.kr/learn/courses/30/lessons/87946#qna

 

프로그래머스

SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

 

 

[소스 코드]

class Solution {
    int n,answer;
    boolean[] visit;
    public int solution(int k, int[][] dungeons) {
        answer = -1;
        n = dungeons.length;
        visit = new boolean[n];
        count(0,k,dungeons);
        return answer;
    }
    private void count(int cnt,int sum,int[][] dungeons){
        answer = Math.max(answer,cnt);
        for(int i=0;i<n;i++){
            if(!visit[i] && dungeons[i][0]<=sum){
                visit[i] = true;
                count(cnt+1,sum-dungeons[i][1],dungeons);
                visit[i] = false;
            }
        }
    }
}