Another approach for Problem 0413 (DFS)
Problem 0413: First idea for dynamic programming.