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 : 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 lowerleft corner to the upperright corner of the grid under these constraints. For example in the following xx grid, one of the cheapest routes of cost 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 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 nonnegative integers representing the costs for the cells. All integers will be separated by spaces. The last problem instance will have values of nm which is not processed.
The input should be taken from keyboardstdinSystemin
Sample Input:
The output for each instance should be a single integer one per line denoting the minimum cost to travel. Print these to the consolestdoutSystemout.
Sample Output:
The above samples are a snippet of a larger whole sample that the code has to go through.
Full sample input:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
