- 난이도: Lv2
프로그래머스 링크: https://school.programmers.co.kr/learn/courses/30/lessons/87946
풀이 링크(GitHub): hayannn/CodingTest_Java/프로그래머스/2/피로도
풀이 시간 : 28분
class Solution {
int answer = 0;
boolean[] visited;
public int solution(int k, int[][] dungeons) {
visited = new boolean[dungeons.length];
dfs(0, k, dungeons);
return answer;
}
public void dfs(int depth, int k, int[][] dungeons) {
answer = Math.max(answer, depth);
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;
}
}
}
}