I am stucked at this problem:
Suppose we have the following grid configuration (or matrix) $G\in \Bbb{M}^{\{0,x,y\}}_{m\times n}$
(I.e $G$ is a matrix that have $m$ rows and $n$ colums over the alphabet $\{0,x,y\}$) $$G= \begin{bmatrix} x & 0 & 0 & \cdots & x \\ 0 & 0 & 0 & \cdots & 0 \\ 0 & y & 0 & \cdots & 0 \\ \vdots & \vdots & \vdots & \ddots & \vdots \\ x & 0& 0& \cdots & x \end{bmatrix} $$
What is the minimal number of steps required for $y$ to visit each of the corners of the grid (I.e.each of the $x$'s in the matrix) where $y$ can move left, right, up and down one cell at a time?
(The $y$ in the grid $G$ was arbitrarily placed, $y$ can be anywhere on the matrix including on the corners).
My try :
The minimum number of steps required for $y$ to visit each of the corners of the grid is at least the sum of manhattan distances from $y$ to each of the corners of the grid, since the minimal number of steps required to reach each corner of the grid is equal to the manhattan distance to that corner, we get that the sum of these distances will be the minimal number of steps required to reach each one of the corners.
Unfortunatley my answer is wrong.
If I take for example the grid: $$G= \begin{bmatrix} x & 0 & 0 & 0 & 0 & x \\ 0 & 0 & 0 & 0 & 0 & 0\\ 0 & 0 & 0 & y & 0 & 0\\ 0 & 0 & 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 0 & 0 & 0\\ x & 0 & 0 & 0 & 0 & x \end{bmatrix} $$
We can see that the minimal number of steps required is actully 19 and not the sum of the manhattan distances which is 20.
Thanks for any hint or help.
(Note: I've encountered this problem while trying to figure out a heuristic for $A^*$ grid search that calculates a path for $y$ that must visit each of the corners of a grid at least once)