← 返回 meta 的题目列表AI Coding Maze: Shortest Path with Keys and Doors (Bitmask State BFS)
类型:online_judge
You are given a maze grid containing:
S (start), E (end), # (wall), . (empty);
keys a-f;
doors A-F (requires the corresponding lowercase key to pass).
Return the shortest number of steps from S to E (4-directional). Return -1 if unreachable.
Your BFS visited must include the key-set state encoded as a bitmask.
Constraints: R,C <= 200, number of key types K <= 6.
Example:
S.a
###
A.E
You must pick up a before passing door A.
Example
Input
3 3
S.a
###
A.E
Output
-1