You are given an n ×n square matrix. Each cell contains a number (positive, negative, or zero); you may assume they are integers if that helps. Now you are thrown into one of the square cells. Your task is to escape the board and at the same time collect as much value as you can. Every time you reach a cell, you gain/lose by the amount stored in that cell. From a cell, you can traverse to a cell below or to the right. You can escape the board from the the right boundary or from the bottom. Note that you cannot go back to a cell that you have already visited; otherwise, you can just keeping visiting two consecutive positive cells and obtain infinite value, yet never escaping – you are filthy rich but alone forever! Give an algorithm to escape as rich as you can be. State the complexity. Your explanation/pseudo-code (if you choose to write one) should be clear; remember that I can only grade based on what you write, not what you thought. You should also provide substantial reasoning as to why your algorithm should work.
You are given an n ×n square matrix. Each cell contains a number (positive,
negative, or zero); you may assume they are integers if that helps. Now you are thrown into one of the square cells. Your task is to escape the board and at the same time collect as much value as you can. Every time you reach a cell, you gain/lose by the amount stored in that cell. From a cell, you can traverse to a cell below or to the right. You can escape the board from
the the right boundary or from the bottom. Note that you cannot go back to a cell that you have already visited; otherwise, you can just keeping visiting two consecutive positive cells and obtain infinite value, yet never escaping – you are filthy rich but alone forever!
Give an
algorithm should work.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps