首页 > TAG信息列表 > startFuel

LeetCode/最低加油次数

汽车从起点出发驶向目的地,该目的地位于出发位置东面 target 英里处。 沿途有加油站,每个 station[i] 代表一个加油站,它位于出发位置东面 station[i][0] 英里处,并且有 station[i][1] 升汽油。 假设汽车油箱的容量是无限的,其中最初有 startFuel 升燃料。它每行驶 1 英里就会

Leetcode 871.最低加油次数(dp / 贪心+优先队列)

  考虑可以用多种解法解决该题。   首先很容易想到用$O(n^2)$的递推dp。设$d[i][j]$为到达第i站前加油次数为j时的最大油量,最后直接找终点最小值就行。鉴于数据规模比较小,stations.length<=500,因此$O(n^2)$是可以通过的。 long long d[503][503]; class Solution { public:

[LeetCode] 871. Minimum Number of Refueling Stops

A car travels from a starting position to a destination which is target miles east of the starting position. There are gas stations along the way. The gas stations are represented as an array stations where stations[i] = [positioni, fueli] indicates tha