LeetCode174-Dungeon Game-数组,动态规划
题目描述
The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Our valiant knight (K) was initially positioned in the top-left room and must fight his way through the > dungeon to rescue the princess.
The knight has an initial health point represented by a positive integer. If at any point his health point drops to 0 or below, he dies immediately.
Some of the rooms are guarded by demons, so the knight loses health (negative integers) upon entering these rooms; other rooms are either empty (0's) or contain magic orbs that increase the knight's health (positive integers).
In order to reach the princess as quickly as possible, the knight decides to move only rightward or downward in each step.
Write a function to determine the knight's minimum initial health so that he is able to rescue the princess.
For example, given the dungeon below, the initial health of the knight must be at least 7 if he follows the optimal path RIGHT-> RIGHT -> DOWN -> DOWN.
分析
自底向上递推更新式:\(M(i,j)=max(0, min(M(i+1,j),M(i,j+1)))\)
解决方案
LeetCode174-Dungeon Game-数组,动态规划的更多相关文章
- HDU 4247 Pinball Game 3D(cdq 分治+树状数组+动态规划)
Pinball Game 3D Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- leetcode-174. Dungeon Game 地下城游戏
一道关于骑士救公主故事的题目. 一些恶魔抓住了公主(P)并将她关在了地下城的右下角.地下城是由 M x N 个房间组成的二维网格.我们英勇的骑士(K)最初被安置在左上角的房间里,他必须穿过地下城并通过 ...
- [LeetCode] 53. Maximum Subarray 最大子数组 --动态规划+分治
Given an integer array nums, find the contiguous subarray (containing at least one number) which has ...
- leetcode 刷题(数组篇)152题 乘积最大子数组 (动态规划)
题目描述 给你一个整数数组 nums ,请你找出数组中乘积最大的连续子数组(该子数组中至少包含一个数字),并返回该子数组所对应的乘积. 示例 1: 输入: [2,3,-2,4] 输出: 6 解释: 子 ...
- leetcode174. Dungeon Game
// learn from https://discuss.leetcode.com/topic/6912/c-dp-solution ''' class Solution { public: int ...
- [Scoi2014]方伯伯的玉米田 二维树状数组+动态规划
考试最后半个小时才做这道题.十分钟写了个暴力还写挂了..最后默默输出n.菜鸡一只. 这道题比较好看出来是动规.首先我们要明确一点.因为能拔高长度任意的一段区域,所以如果从i开始拔高,那么一直拔高到n比 ...
- CF597C Subsequences 树状数组 + 动态规划
设$f(i, j)$表示以$i$结尾的,长为$j$的上升子序列的数量 转移时用树状数组维护即可 复杂度为$O(kn \log n)$ 注:特判0 #include <cstdio> #in ...
- BZOJ4881 线段游戏(二分图+树状数组/动态规划+线段树)
相当于将线段划分成两个集合使集合内线段不相交,并且可以发现线段相交等价于逆序对.也即要将原序列划分成两个单增序列.由dilworth定理,如果存在长度>=3的单减子序列,无解,可以先判掉. 这个 ...
- hdu 1024(滚动数组+动态规划)
Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- ACM学习历程—SNNUOJ 1239 Counting Star Time(树状数组 && 动态规划 && 数论)
http://219.244.176.199/JudgeOnline/problem.php?id=1239 这是这次陕西省赛的G题,题目大意是一个n*n的点阵,点坐标从(1, 1)到(n, n),每 ...
随机推荐
- sizeof操作符的一些例子
例一: #include <iostream> using namespace std; class A { public: char c; }; class B { public: in ...
- Centos7安装并配置mysql5.6
1.下载安装包:https://pan.baidu.com/s/18xAumOggjm9bu9Wty6kYjg 2.卸载系统自带的Mariadb 2.1查询已安装的mariadb [root@loca ...
- java-concurrent包
通常所说的concurrent包基本有3个package组成 java.util.concurrent:提供大部分关于并发的接口和类,如BlockingQueue,Callable,Concurren ...
- linux alias 命令 查看系统设置的命令别名
alias命令用于查看或设置命令别名,但仅作用于该次登陆的会话,若要永久使用别名,可在 ~/.bashrc 中设定别名 [root@MongoDB ~]# alias // 查看别名 [root@Mo ...
- ORACLE——获取随机数
在oracle中获取一个指定的随机数: --(DBMS_RANDOM.VALUE(INT NUM1,INT NUM2),比如: ,) FROM DUAL; --结果:8.23602331029803 ...
- SQL Server get SP parameters and get output fields type information
Summary 本文主要介绍一下,SQL里面的两个很实用的两个操作: 获取存储过程的参数信息 SELECT * FROM INFORMATION_SCHEMA.PARAMETERS WHERE SPE ...
- 从零开始搭建一个vue.js的脚手架
在谷歌工作的时候,我们要做很多界面的原型,要求快速上手,灵活运用,当时用的一些现有框架,比如angular,太笨重了——尤雨溪(Vue.js 作者) vue.js是现在一个很火的前端框架,官网描述其简 ...
- vector创建二位数组
默认初始化vector vector<vevtor<int> > arr(row, vector<int>(col, 0)); //指定行大小为row,列为col, ...
- Excel控制AutoCad进行坐标标注
做过工程测绘,平面设计,使用过Autocad制图的朋友们,都经常要在CAD上标注点或者线的坐标,CAD自身的标注功能,并不能同时标注X和Y坐标,,要同时标注X和Y坐标,可以使用南方CASS软件,或者一 ...
- python3 短网址和数字的相互转换的代码
下面内容是关于python3 短网址和数字的相互转换的内容. import mathimport decimal def convert_to_code(num): """ ...