Question: Need help to finish this C++ Assignment ( shortest path Recursive way ) Below is the Question, Template and the output of shortest path (recursive
Need help to finish this C++ Assignment ( shortest path Recursive way )
Below is the Question, Template and the output of shortest path (recursive way)
Assignment:

Output:
The Output should be look something like this:

#include #include #include using namespace std; const int NUM_ROWS = 5, NUM_COLS = 6; string path[ NUM_ROWS][NUM_COLS]; // Returns the cost of the shortest path from the left to the square in row i, column j. int calculatecost(int i, int j) { static int weight[NUM_ROWS][NUM_COLS] = {{3,4,1,2,8,6}, {6, 1,8, 2,7,4}, {5,9,3,9,9,5}, [8,4,1,3,2,6}, {3,7,2,3,6,4}}; Il Declare the cost matrix. // If the cost has already been calculated, return it. // check for the base case. if (i == 0) { path[i][j] = to_string(i); return weight[i][j]; // calculate the costs of the 3 adjacent squares by calling the function recursively. int up = int left = int down = // Find the minimum of the 3 costs. int mincost = // Update the path matrix (store the path to the current square in path[i][j]): // If up is the minimum, get the shortest path to the up-left square from the path matrix and concatenate it with the current row. path[i][j] = L + to_string(i); // If left is the minimum... // If down is the minimum... // calculate the cost of the current square, store the correct number in the cost matrix, and return the cost