[java] 프로그래머스 - 피로도

0

[문제링크 - 프로그래머스 - 피로도] https://school.programmers.co.kr/learn/courses/30/lessons/87946

import java.util.*;

class Solution {
    static boolean visit[];
    static int answer;
    public int solution(int k, int[][] dungeons) {
        answer = 0;
        visit = new boolean[dungeons.length];
    
        dfs(0, dungeons, k);
        return answer;
    }
    
    public void dfs(int n, int[][] dungeons, int k){
        for(int i=0; i<dungeons.length; i++){
            if(!visit[i] && dungeons[i][0] <= k){
                visit[i] = true;
                dfs(n+1, dungeons, k-dungeons[i][1]);
                visit[i] = false;
            }
        }
        answer = Math.max(answer, n);
    }
}
profile
초심 잃지 않기

0개의 댓글

관련 채용 정보