Write an algorithm for using the merge sort (introduced in the previous lecture) so as to use a dynamic programming approach in case the same list of books must be ordered twice or more times during the algorithm execution – see the informal example introduced in Section "Remembering solutions to sub-problems" of this lecture notes.
Accompany the implementation of the function with the appropriate test cases.