Edsger Dogstra is playing soccer with his friends but someone kicked the ball far away. He has to get the ball, but the soccer field is full of puddles. He hates to step in the puddles, and wants to take the shortest distance where possible.
Help him find the number of different paths of minimum length to reach the ball, where he doesn't step in the puddles!
The soccer field is a square grid, characters are puddles and characters are free grass; Edsger starts in the upper left cell and the ball is in the lower right cell and he can only move on adjacent cells (not diagonally).
It is always possible reach the ball moving only right and down.
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Let f ( n , m ) be the number of paths of minimum length starting in ( n , m ) , it's easy to see that
f ( n ) = ⎩ ⎪ ⎨ ⎪ ⎧ 0 1 1 + f ( n + 1 , m ) + f ( n , m + 1 ) i f n > 2 5 ∨ m > 2 5 ∨ g r i d ( n , m ) = # i f n = 2 5 ∧ m = 2 5 o t h e r w i s e