class Solution {
static boolean[] visited;
static int answer = 0;
static void DFS(int depth, int k, int[][] dungeons){
for(int i=0; i<dungeons.length; i++){
if(!visited[i] && k>=dungeons[i][0]){
visited[i] = true;
DFS(depth+1, k - dungeons[i][1], dungeons);
visited[i] = false;
}
}
answer = Math.max(answer, depth);
}
public int solution(int k, int[][] dungeons) {
visited = new boolean[dungeons.length];
DFS(0, k, dungeons);
return answer;
}
}
'공부기록 > 프로그래머스' 카테고리의 다른 글
[프로그래머스] 최대공약수와 최소공배수 (0) | 2024.02.03 |
---|---|
[프로그래머스] 튜플 (0) | 2024.02.02 |
[프로그래머스] 이진 변환 반복하기 (0) | 2023.12.25 |
[프로그래머스] 모의고사 (1) | 2023.12.23 |
[프로그래머스] 의상 (0) | 2023.12.19 |