From b0df0ff1e94dd7c473afe2eea8c01e0a7080531f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EC=8B=A0=EC=A7=80?= <101992179+ksinji@users.noreply.github.com> Date: Sun, 26 Oct 2025 23:19:45 +0900 Subject: [PATCH] =?UTF-8?q?[20251026]=20PGM=20/=20LV2=20/=20=ED=94=BC?= =?UTF-8?q?=EB=A1=9C=EB=8F=84=20/=20=EA=B0=95=EC=8B=A0=EC=A7=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...M \355\224\274\353\241\234\353\217\204.md" | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 "ksinji/202510/26 PGM \355\224\274\353\241\234\353\217\204.md" diff --git "a/ksinji/202510/26 PGM \355\224\274\353\241\234\353\217\204.md" "b/ksinji/202510/26 PGM \355\224\274\353\241\234\353\217\204.md" new file mode 100644 index 00000000..2c1df069 --- /dev/null +++ "b/ksinji/202510/26 PGM \355\224\274\353\241\234\353\217\204.md" @@ -0,0 +1,29 @@ +```java +class Solution { + static boolean[] visited; + static int answer = 0; + + public int solution(int k, int[][] dungeons) { + visited = new boolean[dungeons.length]; + dfs(k, dungeons, 0); + return answer; + } + + static void dfs(int now, int[][] dungeons, int count) { + if (count > answer) answer = count; + + for (int i = 0; i < dungeons.length; i++) { + if (visited[i]) continue; + + int need = dungeons[i][0]; + int cost = dungeons[i][1]; + + if (now >= need) { + visited[i] = true; + dfs(now - cost, dungeons, count + 1); + visited[i] = false; + } + } + } +} +```