C. Maze Traversal

    传统题 1000ms 256MiB

Maze Traversal

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

Description

There is an m×nm \times n grid maze (indicating mm rows and nn columns), where some cells are passable and others are not. If 1 represents a passable cell and 0 represents an impassable cell, read the m×nm \times n data from the input, along with the starting point and ending point (both described by two values, representing the row number and column number of the point respectively). Your task is to program to find all viable paths under the following rules:

  • No repeated points are allowed in the path.

  • Movement is restricted to the four directions: up, down, left, right.

If there are no viable paths, output the corresponding information (use 1-1 to indicate no path).

Priority order for movement: up, left, right, down. The data is guaranteed to be randomly generated.

Input Format

The first line contains two integers m,nm, n (1<m,n<151 < m, n < 15). Next are mm lines of nn columns of data consisting of 1s and 0s. The last two lines are the starting point and ending point.

Output Format

All viable paths. Each point is described in the form (x, y). Except for the starting point, all other points are connected using -> to denote the direction.

If there are no viable paths, output 1-1.

Sample Input

5 6
1 0 0 1 0 1
1 1 1 1 1 1
0 0 1 1 1 0
1 1 1 1 1 0
1 1 1 0 1 1
1 1
5 6

Sample Output

(1,1)->(2,1)->(2,2)->(2,3)->(2,4)->(2,5)->(3,5)->(4,5)->(5,5)->(5,6)
(1,1)->(2,1)->(2,2)->(2,3)->(2,4)->(2,5)->(3,5)->(3,4)->(4,4)->(4,5)->(5,5)->(5,6)
(1,1)->(2,1)->(2,2)->(2,3)->(2,4)->(2,5)->(3,5)->(3,4)->(3,3)->(4,3)->(4,4)->(4,5)->(5,5)->(5,6)
(1,1)->(2,1)->(2,2)->(2,3)->(2,4)->(3,4)->(3,5)->(4,5)->(5,5)->(5,6)
(1,1)->(2,1)->(2,2)->(2,3)->(2,4)->(3,4)->(4,4)->(4,5)->(5,5)->(5,6)
(1,1)->(2,1)->(2,2)->(2,3)->(2,4)->(3,4)->(3,3)->(4,3)->(4,4)->(4,5)->(5,5)->(5,6)
(1,1)->(2,1)->(2,2)->(2,3)->(3,3)->(3,4)->(3,5)->(4,5)->(5,5)->(5,6)
(1,1)->(2,1)->(2,2)->(2,3)->(3,3)->(3,4)->(2,4)->(2,5)->(3,5)->(4,5)->(5,5)->(5,6)
(1,1)->(2,1)->(2,2)->(2,3)->(3,3)->(3,4)->(4,4)->(4,5)->(5,5)->(5,6)
(1,1)->(2,1)->(2,2)->(2,3)->(3,3)->(4,3)->(4,4)->(4,5)->(5,5)->(5,6)
(1,1)->(2,1)->(2,2)->(2,3)->(3,3)->(4,3)->(4,4)->(3,4)->(3,5)->(4,5)->(5,5)->(5,6)
(1,1)->(2,1)->(2,2)->(2,3)->(3,3)->(4,3)->(4,4)->(3,4)->(2,4)->(2,5)->(3,5)->(4,5)->(5,5)->(5,6)

Note

The data is guaranteed to be randomly generated. In fact, if n=m=14n = m = 14 and every cell is 1, there are 6945066476152136166427470154890735899648869450664761521361664274701548907358996488 paths.

2025XCPC集训队&&算法培训 — 综合训练(一)

未参加
状态
已结束
规则
ACM/ICPC
题目
5
开始于
2025-8-22 19:00
结束于
2025-8-22 22:00
持续时间
3 小时
主持人
参赛人数
21