Question 4
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.
Our approach will be to building a DP table of the same length as the array of disks. Let denote the disk in the input array. The value of will be the height of the tallest tower that can be created with the bottom. We initialize the value of the height of .
Consider the following approach. We process the DP array in increasing order of indices (i.e, to ). We look at all disks where and 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 .
What can you say about this approach?