No.2928 Gridpath
タグ : / 解いたユーザー数 99
作問者 :
kusirakusira
mymelochan
tnodino
Problem Statement
There is a grid with $H$ rows and $W$ columns. The cell in the $i ~ (1 \le i \le H)$-th row from the top and the $j ~ (1 \le j \le W)$-th column from the left is denoted by cell $(i, j)$. Each cell is either an obstacle cell or an empty cell.
From your current cell, you can move to an empty cell adjacent vertically or horizontally. However, you cannot move outside the grid.
Given $S_i, S_j, G_i, G_j$, solve the following problem.
There are $2^{HW - 2}$ grids obtained by placing obstacles on $0$ or more cells other than cells $(S_i, S_j), (G_i, G_j)$ and making the remaining cells empty.
Among the movement paths from cell $(S_i, S_j)$ to cell $(G_i, G_j)$, find the number of movement paths that are shortest in at least one of the $2^{HW - 2}$ grids.
Constraints
- $1 \leq H, W \leq 6$
- $1 \leq S_i, G_i \leq H$
- $1 \leq S_j, G_j \leq W$
- $(S_i, S_j) \neq (G_i, G_j)$
- All input values are integers.
Input
The input is given from standard input in the following format.
$H\ W$ $S_i\ S_j$ $G_i\ G_j$
Output
Output the answer on one line.
Sample
Sample 1
Input
2 3 1 1 1 3
Output
2
The following 2 paths satisfy the condition.
Sample 2
Input
2 6 1 1 1 6
Output
11
The red path is not a shortest path. This is because, on any grid board where the red path exists, the blue path is the shortest path, so the red path can never be a shortest path.
Sample 3
Input
6 6 1 1 1 6
Output
1594
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。