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로 바꿔준다.