题目链接:leetcode
思路:
- 使用动态规划,knight的生命值最少为1
- 初始条件,dp[-1][-1] = max(1-dungeon[-1][-1],1);
dp[i][-1] = max(dp[i+1][-1]-dungeon[i][-1],1)
dp[-1][j] = max(dp[-1][j+1] -dungeon[-1][j],1) - 转移方程,dp[i][j] = max(min(dp[i+1][j],dp[i][j+1])-dungeon[i][j],1)
1 | class Solution(object): |