Dynamic Programming Algorithm Time Complexity