Diwali puzzle (3D-DP)

Here i am not able to figure out overlapping sub-problems.
So the intuition of dp is not coming.
Please tell the subproblems. Also please mention how to think that 3D dp is going to be used over here.

hi @shivashuklamfk_ac4f36cbded466ba have you done basic dp questions? there is a problem called friends pairing problem this is very similar to that do those first.
Do a dry run befire writing code
the no of variables that change is the order of dp here count, prev and i

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.