N - Slimes

I am a beginer at dp .how to solve the following dp problem?
please do not recommend errichto channel.I watched it but did not understand much.


thanks in advance.

Watch this: