The demons had captured the princess and imprisoned her in the bottom-right corner of a
dungeon
. Thedungeon
consists ofm x n
rooms laid out in a 2D grid. Our valiant knight was initially positioned in the top-left room and must fight his way throughdungeon
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 (represented by negative integers), so the knight loses health upon entering these rooms; other rooms are either empty (represented as 0) or contain magic orbs that increase the knight’s health (represented by positive integers).
To reach the princess as quickly as possible, the knight decides to move only rightward or downward in each step.
Return the knight’s minimum initial health so that he can rescue the princess.
给你一个 只包含正整数 的 非空 数组
nums
。请你判断是否可以将这个数组分割成两个子集,使得两个子集的元素和相等。给你一个整数数组
nums
。玩家 1 和玩家 2 基于这个数组设计了一个游戏。玩家 1 和玩家 2 轮流进行自己的回合,玩家 1 先手。开始时,两个玩家的初始分值都是
0
。每一回合,玩家从数组的任意一端取一个数字(即,nums[0]
或nums[nums.length - 1]
),取到的数字将会从数组中移除(数组长度减1
)。玩家选中的数字将会加到他的得分上。当数组中没有剩余数字可取时,游戏结束。如果玩家 1 能成为赢家,返回
true
。如果两个玩家得分相等,同样认为玩家 1 是游戏的赢家,也返回true
。你可以假设每个玩家的玩法都会使他的分数最大化。给定一个整数数组
prices
,其中第prices[i]
表示第i
天的股票价格。设计一个算法计算出最大利润。在满足以下约束条件下,你可以尽可能地完成更多的交易(多次买卖一支股票):
- 卖出股票后,你无法在第二天买入股票 (即冷冻期为 1 天)。
Given a string
s
, return the longest palindromic substring ins
.You are given a 0-indexed binary string
floor
, which represents the colors of tiles on a floor:floor[i] = '0'
denotes that theith
tile of the floor is colored black.- On the other hand,
floor[i] = '1'
denotes that theith
tile of the floor is colored white.
You are also given
numCarpets
andcarpetLen
. You havenumCarpets
black carpets, each of lengthcarpetLen
tiles. Cover the tiles with the given carpets such that the number of white tiles still visible is minimum. Carpets may overlap one another.Return the minimum number of white tiles still visible.