A certain string processing language allows the programmer to break a string into two pieces. It costs n units of time to break a string of n characters into two pieces, since this involves copying the old string. A programmer wants to break a string into many pieces, and the order in which the breaks are made can affect the total amount of time used. For example, suppose we wish to break a 20-character string (for example “abcdefghijklmnopqrst”) after characters at indices 3, 8, and 10 to obtain for (sub)strings: “abcd”, “efghi”, “jk” and “lmnopqrst”. If the breaks are made in left-right order, then the first break costs 20 units of time, the second break costs 16 units of time, and the third break costs 11 units of time, for a total of 47 steps. If the breaks are made in right-left order, the first break costs 20 units of time, the second break costs 11 units of time, and the third break costs 9 units of time, for a total of only 40 steps. How can we find the minimum cost using a dynamic approach and the order of optimal cuts for that minimum cost? The minimal cost and the order of cuts, is 38 and the order of cuts for that is (10,3,8) for this specific word and cuts.
Provide the correct dynamic approach, so far every approach has been working on the length of the string and it is not giving the correct answer, which is 38 and (10, 3, 8) in this case, but should work correctly on other strings and cuts too.