dynamic programming top down approach 2922140