Skip to content

Commit 6441b27

Browse files
committed
deploy: 54c5750
1 parent 63bf83b commit 6441b27

File tree

10 files changed

+7522
-7350
lines changed

10 files changed

+7522
-7350
lines changed

en/lc/864/index.html

Lines changed: 57 additions & 41 deletions
Large diffs are not rendered by default.

en/lc/865/index.html

Lines changed: 127 additions & 49 deletions
Large diffs are not rendered by default.

en/search/search_index.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

en/sitemap.xml

Lines changed: 3464 additions & 3464 deletions
Large diffs are not rendered by default.

en/sitemap.xml.gz

0 Bytes
Binary file not shown.

lc/864/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84988,10 +84988,10 @@ <h3 id="bfs">方法一:状态压缩 + BFS</h3>
8498884988
^ ^ ^ ^
8498984989
f d c b
8499084990
</code></pre></div>
84991-
<p>我们定义一个队列 $q$ 来存储当前位置以及当前拥有的钥匙的状态,即 $(i, j, state)$,其中 $(i, j)$ 表示当前位置,$state$ 表示当前拥有的钥匙的状态,即 $state$ 的第 $i$ 位为 $1$ 表示当前拥有第 $i$ 把钥匙,否则表示当前没有第 $i$ 把钥匙。</p>
84992-
<p>另外,定义哈希表或数组 $vis$ 记录当前位置以及当前拥有的钥匙的状态是否已经被访问过,如果访问过,则不需要再次访问。$vis[i][j][state]$ 表示当前位置为 $(i, j)$,当前拥有的钥匙的状态为 $state$ 时,是否已经被访问过。</p>
84991+
<p>我们定义一个队列 $q$ 来存储当前位置以及当前拥有的钥匙的状态,即 $(i, j, \textit{state})$,其中 $(i, j)$ 表示当前位置,$\textit{state}$ 表示当前拥有的钥匙的状态,即 $\textit{state}$ 的第 $i$ 位为 $1$ 表示当前拥有第 $i$ 把钥匙,否则表示当前没有第 $i$ 把钥匙。</p>
84992+
<p>另外,定义哈希表或数组 $vis$ 记录当前位置以及当前拥有的钥匙的状态是否已经被访问过,如果访问过,则不需要再次访问。$vis[i][j][\textit{state}]$ 表示当前位置为 $(i, j)$,当前拥有的钥匙的状态为 $state$ 时,是否已经被访问过。</p>
8499384993
<p>我们从起点 $(si, sj)$ 出发,将其加入队列 $q$,并将 $vis[si][sj][0]$ 置为 $true$,表示起点位置以及拥有的钥匙的状态为 $0$ 时已经被访问过。</p>
84994-
<p>在广度优先搜索的过程中,我们每次从队首取出一个位置 $(i, j, state)$,并判断当前位置是否为终点,即当前位置是否拥有所有的钥匙,即 $state$ 的二进制表示中的 $1$ 的个数是否为 $k$。如果是,将当前步数作为答案返回。</p>
84994+
<p>在广度优先搜索的过程中,我们每次从队首取出一个位置 $(i, j, \textit{state})$,并判断当前位置是否为终点,即当前位置是否拥有所有的钥匙,即 $state$ 的二进制表示中的 $1$ 的个数是否为 $k$。如果是,将当前步数作为答案返回。</p>
8499584995
<p>否则,我们从当前位置出发,往上下左右四个方向走,如果可以走到下一个位置 $(x, y)$,则将 $(x, y, nxt)$ 加入队列 $q$,其中 $nxt$ 表示下一个位置的钥匙的状态。</p>
8499684996
<p>这里 $(x, y)$ 首先需要满足在网格范围内,即 $0 \leq x &lt; m$ 且 $0 \leq y &lt; n$。其次,如果 $(x, y)$ 位置是墙壁,即 <code>grid[x][y] == '#'</code>,或者 $(x, y)$ 位置是锁,但我们没有对应的钥匙,即 <code>grid[x][y] &gt;= 'A' &amp;&amp; grid[x][y] &lt;= 'F' &amp;&amp; (state &gt;&gt; (grid[x][y] - 'A') &amp; 1) == 0)</code>,则不能走到位置 $(x, y)$。否则,我们可以走到位置 $(x, y)$。</p>
8499784997
<p>搜索结束,没能找到所有的钥匙,返回 $-1$。</p>

lc/865/index.html

Lines changed: 126 additions & 48 deletions
Large diffs are not rendered by default.

search/search_index.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)