Little Red Riding Hood (ZCO '14)

http://www.iarcs.org.in/inoi/2013/zco2013/zco2013-1b.php

I think another dp problem. Totally confused! Anyone who could help me in this one?