Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Note down the different actions that can be done on a piece of wood with dimensions m x n. What do you notice?
If possible, we could sell the m x n piece. We could also cut the piece vertically creating two pieces of size m x n1 and m x n2 where n1 + n2 = n, or horizontally creating two pieces of size m1 x n and m2 x n where m1 + m2 = m.
Notice that cutting a piece breaks the problem down into smaller subproblems, and selling the piece when available is also a case that terminates the process. Thus, we can use DP to efficiently solve this.