1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-03 06:22:54 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
2022-05-02 23:44:12 +08:00
parent 7ea03594b3
commit 2a71c78585
4790 changed files with 11696 additions and 10944 deletions

View File

@@ -12,7 +12,7 @@
"translatedContent": "<p>给你一个 <strong>互不相同</strong>&nbsp;的整数数组,其中&nbsp;<code>locations[i]</code>&nbsp;表示第&nbsp;<code>i</code>&nbsp;个城市的位置。同时给你&nbsp;<code>start</code><code>finish</code>&nbsp;和&nbsp;<code>fuel</code>&nbsp;分别表示出发城市、目的地城市和你初始拥有的汽油总量</p>\n\n<p>每一步中,如果你在城市 <code>i</code>&nbsp;,你可以选择任意一个城市 <code>j</code>&nbsp;,满足 &nbsp;<code>j != i</code>&nbsp;且&nbsp;<code>0 &lt;= j &lt; locations.length</code>&nbsp;,并移动到城市&nbsp;<code>j</code>&nbsp;。从城市&nbsp;<code>i</code>&nbsp;移动到&nbsp;<code>j</code>&nbsp;消耗的汽油量为&nbsp;<code>|locations[i] - locations[j]|</code><code>|x|</code>&nbsp;表示&nbsp;<code>x</code>&nbsp;的绝对值。</p>\n\n<p>请注意,&nbsp;<code>fuel</code>&nbsp;任何时刻都&nbsp;<strong>不能</strong>&nbsp;为负,且你&nbsp;<strong>可以</strong>&nbsp;经过任意城市超过一次(包括&nbsp;<code>start</code>&nbsp;和&nbsp;<code>finish</code>&nbsp;)。</p>\n\n<p>请你返回从<em>&nbsp;</em><code>start</code>&nbsp;到&nbsp;<code>finish</code>&nbsp;所有可能路径的数目。</p>\n\n<p>由于答案可能很大, 请将它对&nbsp;<code>10^9 + 7</code>&nbsp;取余后返回。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<strong>输入:</strong>locations = [2,3,6,8,4], start = 1, finish = 3, fuel = 5\n<strong>输出:</strong>4\n<strong>解释:</strong>以下为所有可能路径,每一条都用了 5 单位的汽油:\n1 -&gt; 3\n1 -&gt; 2 -&gt; 3\n1 -&gt; 4 -&gt; 3\n1 -&gt; 4 -&gt; 2 -&gt; 3\n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre>\n<strong>输入:</strong>locations = [4,3,1], start = 1, finish = 0, fuel = 6\n<strong>输出:</strong>5\n<strong>解释:</strong>以下为所有可能的路径:\n1 -&gt; 0使用汽油量为 fuel = 1\n1 -&gt; 2 -&gt; 0使用汽油量为 fuel = 5\n1 -&gt; 2 -&gt; 1 -&gt; 0使用汽油量为 fuel = 5\n1 -&gt; 0 -&gt; 1 -&gt; 0使用汽油量为 fuel = 3\n1 -&gt; 0 -&gt; 1 -&gt; 0 -&gt; 1 -&gt; 0使用汽油量为 fuel = 5\n</pre>\n\n<p><strong>示例 3</strong></p>\n\n<pre>\n<strong>输入:</strong>locations = [5,2,1], start = 0, finish = 2, fuel = 3\n<strong>输出:</strong>0\n<strong>解释:</strong>没有办法只用 3 单位的汽油从 0 到达 2 。因为最短路径需要 4 单位的汽油。</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>2 &lt;= locations.length &lt;= 100</code></li>\n\t<li><code>1 &lt;= locations[i] &lt;= 10<sup>9</sup></code></li>\n\t<li>所有&nbsp;<code>locations</code>&nbsp;中的整数 <strong>互不相同</strong>&nbsp;。</li>\n\t<li><code>0 &lt;= start, finish &lt;&nbsp;locations.length</code></li>\n\t<li><code>1 &lt;= fuel &lt;= 200</code></li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Hard",
"likes": 60,
"likes": 62,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
@@ -149,7 +149,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"6.3K\", \"totalSubmission\": \"10.6K\", \"totalAcceptedRaw\": 6307, \"totalSubmissionRaw\": 10579, \"acRate\": \"59.6%\"}",
"stats": "{\"totalAccepted\": \"6.8K\", \"totalSubmission\": \"11.5K\", \"totalAcceptedRaw\": 6844, \"totalSubmissionRaw\": 11488, \"acRate\": \"59.6%\"}",
"hints": [
"Use dynamic programming to solve this problem with each state defined by the city index and fuel left.",
"Since the array contains distinct integers fuel will always be spent in each move and so there can be no cycles."