Box stacking problem can't able to pass all test cases.[dp]

where am i doing wrong?

link: https://ide.codingblocks.com/s/243815

@dhruv.160410116084 hey checkout this code ,please:

i am not able to understand you code , can you please tell me where i am doing wrong?

@dhruv.160410116084 hey your dp logic is not upto mark :
1) Generate all 3 rotations of all boxes. The size of rotation array becomes 3 times the size of the original array. For simplicity, we consider width as always smaller than or equal to depth.

2) Sort the above generated 3n boxes in decreasing order of base area.

3) After sorting the boxes, the problem is same as LIS with following optimal substructure property.
MSH(i) = Maximum possible Stack Height with box i at top of stack
MSH(i) = { Max ( MSH(j) ) + height(i) } where j < i and width(j) > width(i) and depth(j) > depth(i).
If there is no such j then MSH(i) = height(i)

4) To get overall maximum height, we return max(MSH(i)) where 0 < i < n

hey , my dp logic is right, but the problem is in rotation so i unlock the editorial and and i came to this line ,
" We can rotate boxes such that width is smaller than depth. "

but i don’t understand this line, pls help.

@dhruv.160410116084 hey please see this short video ,you will get it,and if you still not get it ,I will explain you again,check it:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.