Updated Solution for Lego Blocks. Solution using dynamic programming