class Solution {
    static boolean[] visited;
    static int N;
    static int answer=0;
    public int solution(int k, int[][] dungeons) {
        N = dungeons.length;
        visited = new boolean[N];
        exploreDungeons(k, dungeons,0);
        return answer;
    }
    static void exploreDungeons(int k, int[][] dungeons,int count){
        if(k<0 || count>N) return;
        answer = Math.max(answer,count);
        for(int i=0; i<N; i++){
            if(k>=dungeons[i][0] && visited[i]==false){
                visited[i]=true;
                exploreDungeons(k-dungeons[i][1],dungeons,count+1);
                visited[i]=false;
            }
        }   
    }
}

 

던전을 차례대로 돌며 탐험할 수 있으면 탐험해준다.

던전을 탐험 할 수도 있고 안할 수도 있기 때문에 이후 false로 바꿔준다.

'NOTE > 프로그래머스' 카테고리의 다른 글

가격대 별 상품 개수 구하기 - Oracle  (0) 2022.10.15
소수 찾기  (0) 2022.10.15
모음사전  (1) 2022.10.15
조건별로 분류하여 주문상태 출력하기 - Oracle  (0) 2022.10.12
5월 식품들의 총매출 조회하기  (0) 2022.10.12

+ Recent posts