Question: C++: shortest path problem 1.Modify the code in the handout to include memoization. Modify it additionally so that it prints the actual shortest path as

C++: shortest path problem

1.Modify the code in the handout to include memoization. Modify it additionally so that it prints the actual shortest path as well as its cost. The path should be output as the sequence of rows to choose, going from left to right on the original cost array.

2. Many dynamic programming problems may be solved quite simply from the bottom up. Write a program to solve the shortest path problem using a bottom up approach. The path should be output as the sequence of rows to choose, going from left to right on the original cost array.

sample output:

1 2 3 4 4 5

16

C++: shortest path problem 1.Modify the code in the handout to include

this is some code below:

#include using namespace std; const int rows = 5; const int cols = 6; int cost(int i, int j){ // i is the row, j is the column int weight[rows][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,8,6,4}};

//base case if(j==0) return weight[i][0];

// recursive call int left = ; int up = ; int down = ;

// find the value of the shortest path through cell (i,j) int min = _________

some code goes here

return min; }

int main(){ int ex[rows];

// get the shortest path out of each cell on the right for( int i=0; i

// now find the smallest of them int min= ;

some code goes here

cout

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!