Question: Assignment 3 ( Dynamic Programming ) Assignment Content Using the code posted for Dynamic Programming. Complete both programming codes for ( 1 ) Fibonacci numbers,
Assignment Dynamic Programming
Assignment Content
Using the code posted for Dynamic Programming. Complete both programming codes for
Fibonacci numbers, and for
optional combination numbers using the method of Dynamic Programming.
the code"
def minPathSumgrid:
# Get the number of rows m and columns n
m n lengrid lengrid
# Initialize a D DP array with the same size as the grid
dp n for in rangem
# Base case: the topleft corner is the starting point
dp grid
# Fill the first row can only move right
for j in range n:
dpj dpj gridj
# Fill the first column can only move down
for i in range m:
dpi dpi gridi
# Fill the rest of the DP table
for i in range m:
for j in range n:
dpij mindpi j dpij gridij
# The bottomright corner will have the minimum path sum
return dpm n
# Example usage:
grid
printminPathSumgrid# Output:
You can add time spending to the code for each calculation and compare them with or
without DP for extra points.
You can watch the video posted Unedited video, or the video on Youtube
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
