Question

3. You are in a rectangular maze organized in the form of M x N cells/locations. You are starting at the upper left corner (g

Once you reach the destination your earnings is the difference between earnings and costs. Give an algorithm that will output

0 0
Add a comment Improve this question Transcribed image text
Answer #1

This problem can be solved by dynamic programming algorithm where if P[i][j] is the maximum profit achievable when reaching from (1,1) to (i,j) .

Then the dynamic programming recurrence relation for computing P[i+1][j+1] will be given by

P[i+1][j+1] = max(P[i+1][j] -2, P[i][j+1] -2 , P[i][j] - 3) + Value[i+1][j+1]

Here Value[i][j] will be earning associated with grid [i][j].

Above dynamic programming recurrence check maximum earning when [i+1][j+1] entered either from [i][j] with cost 3, [i][j+1] or from [i+1][j] with cost 2.

Let's formally write the algorithm .

ALGORITHM()

1. P[1][1]= Value [1][1] //base case

2. For i = 2 to M

3.......P[i][1] = P[i-1][1] + Value[i][1] - 2 //only one way here

4. For j = 2 to N

5.......P[1][j] = P[1][j-1] + Value[1][j]-2 //only one way here

6. For i = 2 to M

7.........For j = 2 to N

8...............P[i][j] = max(P[i-1][j]-2, P[i][j-1]-2, P[i-1][j-1]-3) + Value[i][j]

9. Return P[M][N] //since this is the final solution calculated

Time complexity O(MN).

Please comment for any clarification.

Add a comment
Know the answer?
Add Answer to:
3. You are in a rectangular maze organized in the form of M x N cells/locations....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PLEASE ANSWER IN C++! Given the starting point in a maze, you are to find and...

    PLEASE ANSWER IN C++! Given the starting point in a maze, you are to find and mark a path out of the maze, which is represented by a 20x20 array of 1s (representing hedges) and 0s (representing the foot-paths). There is only one exit from the maze (represented by E). You may move vertically or horizontally in any direction that contains a 0; you may not move into a square with a 1. If you move into the square with...

  • Maze Solving with Stacks Problem Statement Consider a maze made up of rectangular array of squares,...

    Maze Solving with Stacks Problem Statement Consider a maze made up of rectangular array of squares, such as the following one: X X X X X X X X X X X X X           X            X X X X    X X X           X               X     X X X     X X    X    X     X     X X X         X          X             X X X     X X X X X                X X X X X X X X X X X X X Figure...

  • The Problem A robot is asked to navigate a maze. It is placed at a certain...

    The Problem A robot is asked to navigate a maze. It is placed at a certain position (the starting position) in the maze and is asked to try to reach another position (the goal position). Positions in the maze will either be open or blocked with an obstacle. Positions are identified by (x,y) coordinates. At any given moment, the robot can only move 1 step in one of 4 directions. Valid moves are: ● Go North: (x,y) -> (x,y-1) ●...

  • This lab will use 2D arrays, recursive algorithms, and logical thinking. The following grid of hashes(#)...

    This lab will use 2D arrays, recursive algorithms, and logical thinking. The following grid of hashes(#) and dots(.) is a 2D array representation of a maze # # # # # # # # # # # # # . . . # . . . . . . # . . # . # . # # # # . # # # # . # . . . . # . # # . . . . #...

  • Need help!! Java Eclipse Please provide the screenshot of output of code as well. thank you......

    Need help!! Java Eclipse Please provide the screenshot of output of code as well. thank you... PROGRAM 1 –Linear Data Structure Implementation (Due date: March 5th, 2019, 5% Grade Points) Given the starting point in a maze, you are to find and mark a path out of the maze which is represented by a 30x30 array of 1s (representing hedges) and 0s (representing the foot-paths). There is only one exit from the maze (represented by E). You may move vertically...

  • In this part, you will complete the code to solve a maze.

    - Complete the code to solve a maze- Discuss related data structures topicsProgramming-----------In this part, you will complete the code to solve a maze.Begin with the "solveMaze.py" starter file.This file contains comment instructions that tell you where to add your code.Each maze resides in a text file (with a .txt extension).The following symbols are used in the mazes:BARRIER = '-' # barrierFINISH = 'F' # finish (goal)OPEN = 'O' # open stepSTART = 'S' # start stepVISITED = '#' #...

  • There are n trading posts numbered 1 to n as you travel downstream. At any trading...

    There are n trading posts numbered 1 to n as you travel downstream. At any trading post i you can rent a canoe to be returned at any of the downstream trading posts j>i. You are given a cost array R(i,j) giving the cost of these rentals for all 1≤i<j≤n. We can assume that R(i,i)=0, and that you can't go upriver (so perhaps R(i,j)= ∞ if i>j). For example, one cost array with n=4 might be the following. The problem...

  • You must use recursion to solve each problem. You cannot use loops in this homework. You...

    You must use recursion to solve each problem. You cannot use loops in this homework. You cannot import any module. A couple of the tasks have individual restrictions; note them, as we will remove points for any task that does not follow the requirements. def factorial_evens(num): Implement a function to calculate and return the product of all even numbers from 1 up to num (inclusive if num is even). o Assumption: num will be an integer greater than or equal...

  • 3.Question for further thought Imagine the two-dimensional space {0, 1, . . . , 10).(0, 1,...

    3.Question for further thought Imagine the two-dimensional space {0, 1, . . . , 10).(0, 1, . . . , 10) = (0,0), (0,1),(10, 10)J. We locate a mouse on the (0,0) point and we locate a piece of cheese on the (10, 10) point. We somehow make sure that the mouse will reach the cheese with 20 steps, by either going steps 'right' (for example, from (0, 0) to (0,1)) or by going steps 'up' (for example, from (0,0)...

  • In traditional Tic Tac Toe game, two players take turns to mark grids with noughts and...

    In traditional Tic Tac Toe game, two players take turns to mark grids with noughts and crosses on the 3 x 3 game board. The player who succeeds in placing three of their marks in a horizontal, vertical, or diagonal row in the game board wins the game. Super Tic Tac Toe game also has a 3 x 3 game board with super grid. Each super grid itself is a traditional Tic Tac Toe board. Winning a game of Tic...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT