Calculates the nth Fibonacci number using dynamic programming to avoid redundant calculations.
The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones. This algorithm uses dynamic programming to store the results of subproblems to avoid redundant calculations.