Bear and Haircut ,please tell me how to approach this problem , editorial is incomplete

dynamic-programming
ltime49
medium

#1

HAIRCUT
I am unable to form recurrence ,please help and editorial is not complete of this problem.editorial