We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
You are calculating tn by solving the problem from t1 to tn, and recording the results in order to calculate the one you need.
That's the whole idea of dynamic programming: to solve a complex instance of a problem using the solution to smaller instances.
This problem is so simple that you can't really appreciate the technique. If you want an example of a more "serious" DP algorithm, you might look to a classic like the Wagner–Fischer algorithm to compute the distance between strings. It's simple enough but not trivial.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Fibonacci Modified
You are viewing a single comment's thread. Return to all comments →
Your solution is a DP solution.
You are calculating tn by solving the problem from t1 to tn, and recording the results in order to calculate the one you need.
That's the whole idea of dynamic programming: to solve a complex instance of a problem using the solution to smaller instances.
This problem is so simple that you can't really appreciate the technique. If you want an example of a more "serious" DP algorithm, you might look to a classic like the Wagner–Fischer algorithm to compute the distance between strings. It's simple enough but not trivial.