New solution using dynamic programming for max_path problem