풀이 방법
dfs를 이용해서 모든 경로를 탐색하는 방법을 선택했다.
내 코드
class Solution {
private static int max = -1;
private static boolean[] check;
public int solution(int k, int[][] dungeons) {
check = new boolean[dungeons.length];
dfs(dungeons, k, 0);
return max;
}
private static void dfs(int[][] dungeons, int k, int count){
if(count > max){
max = count;
}
for(int i = 0; i < dungeons.length; i++){
if(!check[i] && dungeons[i][0] <= k){
check[i] = true;
dfs(dungeons, k - dungeons[i][1], count + 1);
check[i] = false;
}
}
}
}
'코딩테스트 > [프로그래머스] 코딩테스트 연습' 카테고리의 다른 글
등굣길 (0) | 2021.11.22 |
---|---|
N으로 표현 (0) | 2021.11.19 |
가장 먼 노드 (0) | 2021.10.22 |
순위 (0) | 2021.10.22 |
추석 트래픽 (0) | 2021.10.21 |