Question 5
We are given a non-empty list of N ordered triplets where each triplet holds three integers and represents a cuboid-shaped disk. These integers denote each disk’s width, depth, and height, respectively. Your goal is to stack up the disks and to maximize the total height of the stack. A disk must have a strictly smaller width, depth, and height than any other disk below it.
Our goal is to design an algorithm that returns the total height of the optimal stack, starting with the top disk and ending with the bottom disk. Note that you can’t rotate disks. You can assume that there will only be one stack with the greatest total height. We also use 1-based indexing in the subquestions.
Based on the above data, answer the given subquestions.
With the same notation as in the previous question, consider the following alternate approach.We process the DP array in increasing order of indices (i.e, to ). We look at all disks such that can be placed on top of . If can be placed on top of , then is updated to be the maximum of and , where is the height of the disk .
Note that the DP array is initialized as before, that is, is initialized to the height of . What can you say about this approach?