Lego Box Dynamic Programming

algorithm

#1

Guys, need help for this problem https://www.hackerrank.com/challenges/lego-blocks

How can I formulate DP for this problem