mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-13 19:31:42 +08:00
add leetcode problem-cn part6
This commit is contained in:
57
算法题(国内版)/problem (Chinese)/地下城游戏 [dungeon-game].html
Normal file
57
算法题(国内版)/problem (Chinese)/地下城游戏 [dungeon-game].html
Normal file
@@ -0,0 +1,57 @@
|
||||
<style>
|
||||
|
||||
table.dungeon, .dungeon th, .dungeon td {
|
||||
|
||||
border:3px solid black;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
.dungeon th, .dungeon td {
|
||||
|
||||
text-align: center;
|
||||
|
||||
height: 70px;
|
||||
|
||||
width: 70px;
|
||||
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
|
||||
|
||||
<p>一些恶魔抓住了公主(<strong>P</strong>)并将她关在了地下城的右下角。地下城是由 M x N 个房间组成的二维网格。我们英勇的骑士(<strong>K</strong>)最初被安置在左上角的房间里,他必须穿过地下城并通过对抗恶魔来拯救公主。</p>
|
||||
|
||||
|
||||
|
||||
<p>骑士的初始健康点数为一个正整数。如果他的健康点数在某一时刻降至 0 或以下,他会立即死亡。</p>
|
||||
|
||||
|
||||
|
||||
<p>有些房间由恶魔守卫,因此骑士在进入这些房间时会失去健康点数(若房间里的值为<em>负整数</em>,则表示骑士将损失健康点数);其他房间要么是空的(房间里的值为 <em>0</em>),要么包含增加骑士健康点数的魔法球(若房间里的值为<em>正整数</em>,则表示骑士将增加健康点数)。</p>
|
||||
|
||||
|
||||
|
||||
<p>为了尽快到达公主,骑士决定每次只向右或向下移动一步。</p>
|
||||
|
||||
|
||||
|
||||
<p> </p>
|
||||
|
||||
|
||||
|
||||
<p><strong>编写一个函数来计算确保骑士能够拯救到公主所需的最低初始健康点数。</strong></p>
|
||||
|
||||
|
||||
|
||||
<p>例如,考虑到如下布局的地下城,如果骑士遵循最佳路径 <code>右 -> 右 -> 下 -> 下</code>,则骑士的初始健康点数至少为 <strong>7</strong>。</p>
|
||||
|
||||
|
||||
|
||||
<table class="dungeon">
|
||||
|
||||
<tr>
|
||||
|
||||
<td>-2 (K)</td>
|
Reference in New Issue
Block a user