【LeetCode】地下城游戏(动态规划)

地下城游戏

链接: 地下城游戏

题目描述

算法分析

编程代码

cpp 复制代码
class Solution {
public:
    int calculateMinimumHP(vector<vector<int>>& dungeon) {
        int m = dungeon.size();
        int n = dungeon[0].size();

        vector<vector<int>> dp(m+1,vector<int>(n+1,INT_MAX));
        dp[m][n-1] = dp[m-1][n] = 1;
        for(int i = m-1;i>=0;--i)
        {
            for(int j = n-1;j>=0;--j)
            {
                dp[i][j] = min(dp[i+1][j],dp[i][j+1]) - dungeon[i][j];
                dp[i][j] = max(1,dp[i][j]);
            }
        }
        return dp[0][0];
    }
};
相关推荐
Nil2085 小时前
leetcode 49字母异位分组
算法·leetcode·哈希算法
Nil20820 小时前
leetcode 5最长回文子串
算法·leetcode·职场和发展
m0_6745719720 小时前
力扣 hot 100 python
python·算法·leetcode
圣保罗的大教堂21 小时前
leetcode 3727. 最大交替平方和 中等
leetcode
Xin7701 天前
LeetCode 200. 岛屿数量(DFS 深度优先遍历法)
leetcode
alphaTao1 天前
LeetCode 每日一题 2026/10/12-2026/10/18
算法·leetcode
Cccp.1231 天前
【leetcode】(十三)大数据处理
数据结构·算法·leetcode
Pniubi1 天前
力扣70爬楼梯
数据结构·算法·leetcode
Navigator_Z2 天前
LeetCode //C - 1293. Shortest Path in a Grid with Obstacles Elimination
c语言·算法·leetcode
Nil2082 天前
leetcode 64最小路径和
算法·leetcode·职场和发展