Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a code in C++ that does the following task. A robot is at the top left of

ID: 3757359 • Letter: W

Question

Write a code in C++ that does the following task.

A robot is at the top left of an N × N grid, and needs to get to the bottom right in order

to paint his message. To reach his destination as soon as possible, he’ll only move along the

shortest way, by moving right and down only.

The robot can encounter obstacles marked as negative numbers,

where the magnitude is the amount of damage they deal.

The positive numbers are tiles that heal the robot that amount of HP, P are tiles that prevent

the robot’s next damage, and D are tiles that double the robot’s next healing effect.

If the robot reaches 0 HP or less, he collapses and the mission fails, so prevent that!

No matter how many P tiles and D tiles the robot encounters, their effects don’t stack.

For example, if the robot walks on a D tile when he’s already in the state of “doubling next healing

effect”, nothing happens. When the robot next encounters a healing tile, the healing will be doubled.

Afterwards, the robot returns to a “normal” state. The same applies for P tiles.

What is the minimum amount of life the robot needs in order to complete his task?

Explanation / Answer

#include<iostream>

#include<vector>

using namespace std;

int get_unique_paths(int m, int n)

{

int path [m] [n];

// Base condition

// initialize first row to 1

for (int j = 0; j < n; ++j)

{

path[0][j] = 1;

}

// Base condition

// initialize first column to 1

for (int j = 0; j < n; ++j)

{

path[j][0] = 1;

}

// apply the formula Paths[i][j] = Paths[i - 1][j] + Paths[i][j - 1]

for (int i = 1; i < m; i++)

for (int j = 1; j < n; j++)

path[i][j] = path[i - 1][j] + path[i][j - 1];

for (int i = 0; i < m; i++){

for (int j = 0; j < n; j++){

cout << path[i][j] <<" ";

}

cout<<endl;

}

return path[m - 1][n - 1];

}

int main()

{

int m = 4;

int n = 4;

int result = get_unique_paths(m, n);

cout<<"The number of unique paths for a "<<m <<" x "<< n<<" matrix is = "<< result<<endl;

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote