Dynamic Programming Approach Algorithm And Complexity Analysis