Completed dynamic programming problem. SRM-585-DIV-2/500