Good metric, good recursion

George has two 10 foot boards. He wants to saw his boards to get pieces of 6 feet, 5 feet, 4 feet, 3 feet and 2 feet. So he uses his first board to saw a 5-foot piece and a 4-foot piece. He uses his second plank to get pieces of 6 feet and 3 feet. He then ends up with two 1-foot scraps and still has not produced the 2-foot piece. George then realizes that if he had used dynamic programming, he would have cut his boards differently: 6 feet + 4 feet = 10 feet and 5 feet + 3 feet + 2 feet = 10 feet.

I want to design a dynamic programming algorithm taking as input two board lengths L0 and L1 and a list of m lengths of pieces [M_0, M_1,. . . , M_ {m − 1}]. This algorithm must return a vector of size m containing the number of the board in which the piece will be cut. In the previous example, the algorithm receives as input the lengths of boards L_0 = 10 and L_1 = 10 and the list of pieces [6 feet, 5 feet, 4 feet, 3 feet, 2 feet] and returns the vector as output [0, 1, 0, 1, 1]. The vector [1, 0, 1, 0, 0] is also a valid solution for this problem. Not sure where to start. I know I have to create a table where the axis are probably the length of the first plank L_0 and the length of the second plank L_1 in feet. I just not sure about the metric to use and how to define it recursively. What could be a good recurrence relation?

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum