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; + } + } + } +} +```