Dynamic programming is a method for solving complex problems by breaking them down into simpler subproblems. Matrix chain multiplication is an example where a chain of matrices can be multiplied together in different orders, and dynamic programming can be used to find the most efficient order that minimizes the number of scalar multiplications needed. The algorithm works by defining the problem recursively as calculating the minimum number of multiplications needed to multiply matrices Mi to Mj for all relevant ranges of i and j, filling a table with these values before returning the overall optimal solution.