Lego Box Dynamic Programming

Guys, need help for this problem Lego Blocks | HackerRank

How can I formulate DP for this problem