230909 피로도

Jongleee·2023년 9월 9일
0

TIL

목록 보기
360/576
public int solution(int k, int[][] dungeons) {
	boolean[] visited = new boolean[dungeons.length];
	return dfs(0, k, dungeons, visited);
}

public static int dfs(int depth, int k, int[][] dungeons, boolean[] visited) {
	int maxDepth = depth;

	for (int i = 0; i < dungeons.length; i++) {
		if (!visited[i] && dungeons[i][0] <= k) {
			visited[i] = true;
			int subDepth = dfs(depth + 1, k - dungeons[i][1], dungeons, visited);
			maxDepth = Math.max(maxDepth, subDepth);
			visited[i] = false;
		}
	}

	return maxDepth;
}

출처:https://school.programmers.co.kr/learn/courses/30/lessons/87946

0개의 댓글