个人主页:Lei宝啊
愿所有美好如期而遇
地下城游戏https://leetcode.cn/problems/dungeon-game/description/
图解+分析:
代码
class Solution
{
public:
int calculateMinimumHP(vector<vector<int>>& vv)
{
int row = vv.size(), col = vv[0].size();
vector<vector<int>> dp(row+1, vector<int>(col+1, INT_MAX));
dp[row][col-1] = dp[row-1][col] = 1;
for(int i=row-1; i>=0; i--)
{
for(int j=col-1; j>=0; j--)
{
int blood = max(1, min(dp[i+1][j], dp[i][j+1]) - vv[i][j]);
dp[i][j] = blood;
}
}
return dp[0][0];
}
};
标签:游戏,int,col,vector,vv,地下城,leetcode,dp,row
From: https://blog.csdn.net/m0_74824254/article/details/139217409