cswork / OA打开练习工作台

WeRideOA #3

Bob Navigates a Maze (BFS, Collect All Gold)

估计困难评测数据准备中,可先阅读题面

考点(AI 标注)最短路树形博弈网格搜索

Bob and Alice have teamed up on a game where, after winning the first round, they now have access to a maze with hidden gold. If Bob can collect all the gold coins and deliver them to Alice, they can split the gold. Bob can move horizontally or vertically as long as he stays in the maze, and the cell is not blocked.

The maze is represented by an n × m array. Each cell has a value, where 0 is open, 1 is blocked, and 2 is open and contains a gold coin. Bob starts at the top left position (0, 0), and Alice's position is given by (x, y). Determine the shortest path Bob can take to collect all gold coins and deliver them to Alice. If Bob can't collect and give all the gold coins, return -1.