Search⌘ K
AI Features

Solution: Dungeon Game

Explore a dynamic programming approach to solve the dungeon game problem. Understand how to compute the minimum initial health a knight needs to safely navigate a grid with health effects, ensuring survival while rescuing the princess. This lesson walks you through backward calculation, memoization, and tabulation strategies essential for optimizing complex pathfinding problems.

Statement

A group of demons has captured a princess and locked her in the bottom-right corner of a dungeon. The dungeon is represented as a 2D grid of size m×nm × n, where each cell contains an integer value that affects the knight’s health.

The knight, starting in the top-left corner of the grid, must travel through the dungeon to rescue the princess.
He can move only to the right or downward at each step.

  • If a cell ...