https://school.programmers.co.kr/learn/courses/30/lessons/87946
const solution = (k, dungeons) => {
let answer = 0;
const visit = Array.from({ length: dungeons.length }, (_) => false);
const dfs = (k, cnt) => {
for (const i in dungeons) {
const [need, consume] = dungeons[i];
if (!visit[i] && k >= need) {
visit[i] = true;
dfs(k - consume, cnt + 1);
visit[i] = false;
}
}
answer = Math.max(answer, cnt);
};
dfs(k, 0);
return answer;
};
'Coding Test > Programmers' 카테고리의 다른 글
[Programmers Test] (1회차 코딩테스트) No 3. Stock (1) | 2023.01.20 |
---|---|
[Programmers Test] (1회차 코딩테스트) No 2. TakeTheSand (0) | 2023.01.20 |
[Programmers] (탐욕법[Greedy]) Lv 2. 구명보트 (0) | 2023.01.17 |
[Programmers] Lv 1. 콜라츠 추측 (0) | 2023.01.17 |
[Programmers] Lv 2. 귤 고르기 (0) | 2023.01.16 |
댓글