SERGRID  Grid
You are on an nxm grid where each square on the grid has a digit on it. From a given square that has digit k on it, a Move consists of jumping exactly k squares in one of the four cardinal directions. A move cannot go beyond the edges of the grid; it does not wrap. What is the minimum number of moves required to get from the topleft corner to the bottomright corner?
Input
Each input will consist of a single test case. Note that your program may be run multiple times on different inputs. The first line of input contains two spaceseparated integers n and m (1≤n,m≤500), indicating the size of the grid. It is guaranteed that at least one of n and m is greater than 1. The next n lines will each consist of m digits, with no spaces, indicating the nxm grid. Each digit is between 0 and 9, inclusive. The topleft corner of the grid will be the square corresponding to the first character in the first line of the test case. The bottomright corner of the grid will be the square corresponding to the last character in the last line of the test case.
Output
Output a single integer on a line by itself representing the minimum number of moves required to get from the topleft corner of the grid to the bottomright. If it isn’t possible, output 1.
Example
Input: 5 4
2120
1203
3113
1120
1110
Output: 6
hide comments
vengatesh15:
20170131 06:59:34
easy bfs.. 

namlunoy:
20161107 10:32:00
DFS > TLE Last edit: 20161107 10:32:47 

avisheksanvas:
20160709 09:27:06
Remember > If it isnâ€™t possible, output 1. 

rjgames:
20160414 09:54:27
Explanation of test case: (1 indexed)


Sushovan Sen:
20160331 10:02:36
Can someone please explain the test cases..

Added by:  Joshua Kirstein 
Date:  20160329 
Time limit:  1s2s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: ASM64 GOSU JSMONKEY 
Resource:  ACM SER 2015 