Question: Problem 2 : Shortest Cost Route to Navigate a Grid Consider a grid where each cell has a different cost to travel across the regions.

Problem 2: Shortest Cost Route to Navigate a Grid
Consider a grid where each cell has a different cost to travel across the regions. Assume we can only travel and stop in straight lines between the corners of these cells. Note that the cost to travel along a border between two cells is the cheapest of the two. We want to find the cheapest route from the lower-left corner to the upper-right corner of the grid under these constraints. For example in the following 3xx3 grid, one of the cheapest routes of cost 2+3+4+2=11 is highlighted. We will read in a sequence of problem instances. The first line will contain two positive integers n and m, both at most 400, denoting the dimensions of the grid; here the number of rows is n and the number of columns is m. We then are given n lines of m non-negative integers representing the costs for the cells. All integers will be separated by spaces. The last problem instance will have values of n=m=0, which is not processed.
The input should be taken from keyboard/stdin/System.in.
Sample Input:
33
062
184
237
35
13991
510184
27826
00
The output for each instance should be a single integer (one per line) denoting the minimum cost to travel. Print these to the console/stdout/System.out.
Sample Output:
11
17
The above samples are a snippet of a larger whole sample that the code has to go through.
Full sample input:
33
062
184
237
35
13991
510184
27826
810
38121851710141014
121511510159590
1879451121713
715012161711559
134122010190
1312515144616172
100111118107932
121514521591375
810
277866889955828916363381261284
226664429489287881367505552582
94199353651191871852592965
817930189908903258163320794366
497826706679882737829890576666
507644536937649238386320127283
597715487287312122874611842696
94176049950230840057227851253
810
4861517389170772010821897391217591898
172837143636239427173287615154327493339
23263315447135111137341336138836983749
3209163629253327216619032239202615803479
26221105928291618361623256015651699811
2875720397428731799932363260919033721
3511172947359592457615244428822671
22452425368618831427136350430922833736
610
403519372321301524
2329232201834221127
13132237301618322625
7103512832335334
25232626272016362740
1010736281319294022
68
35311322053033
142152930372422
36392112312911
44273032311412
3563174202527
579214181924
67
12456476
13101161228
4101225510
3961112412
127010891
1010

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!