문제 풀이
오늘의 문제 - 프로그래머스.피로도
나의 풀이
class Solution {
public static int answer;
public static boolean[] visited;
public static int solution(int k, int[][] dungeons) {
answer = 0;
visited = new boolean[dungeons.length];
backTracking(0, k, dungeons);
return answer;
}
public static void backTracking(int depth, int k, int[][] dungeons) {
for (int i = 0; i < dungeons.length; i++) {
if (!visited[i] && dungeons[i][0] <= k) {
visited[i] = true;
backTracking(depth + 1, k - dungeons[i][1], dungeons);
visited[i] = false;
}
}
answer = Math.max(answer, depth);
}
}