← 返回 meta 的题目列表Maze Solver: Shortest Path With Keys and Doors (Stateful BFS)
类型:online_judge
Problem: Shortest Path in a Maze with Keys and Doors
You are given an R x C maze:
#: wall
S: start
E: exit
.: open cell
a-f: keys
A-F: doors (door A can be passed only if you have key a)
Move 4-directionally; each move costs 1.
Return the minimum number of steps from S to E, or -1 if unreachable.
Input
First line: R C
Next R lines: strings of length C
Output
Minimum steps or -1
Constraints
1 <= R, C <= 200
At most 6 distinct key types (a-f)
Note
You may need to revisit a cell after picking up a key, so the visited state cannot be just (r, c).
Example
Input
3 4
S.a#
##A.
...E
Output
-1