You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This discussion was converted from issue #28 on September 15, 2026 11:00.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Problem link
https://leetcode.com/problems/dungeon-game/
Problem Summary
2차원 던전이 있고 가장 오른쪽 아래의 공주를 구해야 한다.
각 배열의 값에 해당하는 만큼의 체력이 깎이거나 증가될 때, 공주를 구하려면 필요한 최소의 체력을 구하는 문제.
Solution
전형적인 DP이다.
특히 거꾸로 올라가는 방향이 없을 경우 (이 문제에서는 오른쪽와 아래 방향으로만 갈 수 있다) 거의 DP로 풀 수 있다.
으로 정의하면 DP[x][y] = min(DP[x+1][y], DP[x][y + 1]) 이런 느낌으로 top-down DP를 짤 수 있다. 여기서는 체력이 최소 1 이상 남겨야 하므로 이것만 처리해주면 된다.
Source Code
All reactions