Dungeon Game
典型的动态规划题。维护一个二维数组dungeon,dungeon[i][j]表示从第i行第j出发到终点所需要的最低血量(包含当前位置的消耗),最低血量不大于1。
递推公式为:
1 | dungeon[i][j] = Math.max(1, -dungeon[i][j] + Math.min(dungeon[i + 1][j], dungeon[i][j + 1])); |
实现代码:
1 | public class Solution { |
典型的动态规划题。维护一个二维数组dungeon,dungeon[i][j]表示从第i行第j出发到终点所需要的最低血量(包含当前位置的消耗),最低血量不大于1。
递推公式为:
1 | dungeon[i][j] = Math.max(1, -dungeon[i][j] + Math.min(dungeon[i + 1][j], dungeon[i][j + 1])); |
实现代码:
1 | public class Solution { |
原文作者: findingsea
原文链接: http://findingsea.github.io/2015/05/06/dungeon-game-at-leetcode/
发表日期: May 6th 2015, 10:45:00 am
版权声明: 本文采用知识共享署名-非商业性使用 4.0 国际许可协议进行许可
jsonContent:
meta: false
pages: false
posts:
title: true
date: true
path: true
text: false
raw: false
content: false
slug: false
updated: false
comments: false
link: false
permalink: false
excerpt: false
categories: true
tags: true