#P1605. Unique Paths in a Maze

    ID: 14891 Type: Default 1000ms 256MiB

Unique Paths in a Maze

Unique Paths in a Maze

You are given a maze represented as a N×MN \times M grid. In the maze, there are TT obstacles, and the obstacle cells are impassable. You are allowed to move in the four cardinal directions: up, down, left, and right; each move takes you one cell. Each cell can be visited at most once in a single path. Given the starting coordinates and the target coordinates, determine the number of distinct paths from the start to the target. It is guaranteed that the start cell does not contain an obstacle.

inputFormat

The input begins with three integers separated by spaces: NN, MM, and TT, representing the number of rows, columns, and obstacles respectively.

Then follow TT lines, each containing two integers rr and cc (1-indexed) which denote the coordinates of an obstacle cell.

Next, a line follows with two integers sxs_x and sys_y, representing the starting cell's coordinates.

Finally, a line with two integers txt_x and tyt_y is given, representing the target cell's coordinates.

outputFormat

Output a single integer representing the number of distinct paths from the starting cell to the target cell under the given constraints.

sample

2 2 0
1 1
2 2
2