Diwali Puzzle Problem

Can u please explain why we are using 3d dp here not 2d dp