From 288a9fdc10fffcbd2b34c3369cc879346f12d186 Mon Sep 17 00:00:00 2001 From: JuneHee Date: Mon, 29 Apr 2024 11:07:19 +0900 Subject: [PATCH] =?UTF-8?q?[PGM]=20=ED=94=BC=EB=A1=9C=EB=8F=84=20/=20Level?= =?UTF-8?q?=202=20/=20=EC=8B=A4=ED=8C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\355\224\274\353\241\234\353\217\204.js" | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 "junehee/\355\224\274\353\241\234\353\217\204.js" diff --git "a/junehee/\355\224\274\353\241\234\353\217\204.js" "b/junehee/\355\224\274\353\241\234\353\217\204.js" new file mode 100644 index 0000000..139ed98 --- /dev/null +++ "b/junehee/\355\224\274\353\241\234\353\217\204.js" @@ -0,0 +1,19 @@ +function solution(k, dungeons) { + let count = []; + let visited = new Array(dungeons.length).fill(false); + + function DFS(K, L) { + count.push(L); + for (let i = 0; i < dungeons.length; i++) { + if (!visited[i] && dungeons[i][0] <= K) { + visited[i] = true; + DFS(K - dungeons[i][1], L + 1); + visited[i] = false; + } + } + } + + DFS(k, 0) + + return Math.max(...count); +}