forked from wisdompeak/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bce5828
commit f3b3b14
Showing
1 changed file
with
10 additions
and
0 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
Dynamic_Programming/2214.Minimum-Health-to-Beat-Game/Readme.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
### 2214.Minimum-Health-to-Beat-Game | ||
|
||
我们用dp0[i]表示通过第i关时仍未使用盔甲能够存留的最大血量,dp1[i]表示通过第i关时已经使用盔甲能够存留的最大血量,于是转移方程就是 | ||
``` | ||
dp0[i] = dp0[i] - damage[i]; | ||
dp1[i] = max(dp1[i] - damage[i], dp0[i] - max(0, damage[i]-armor)); | ||
``` | ||
我们假设初始血量是0,模拟走一遍上面的流程。由此,```max(dp0[i], dp1[i])```表示的就是通过第i关所能存留的最大血量。 | ||
|
||
要保证在通过的过程中的最大血量始终都大于0,那么就观察所有```max(dp0[i], dp1[i])```里的最低点,通过加上这个offset来保证全程的血量都不低于1. |