How to solve grid problems like problem H1?

How to approach and solve grid problems like as given below or any other kind of such problems ?

It is quit difficult for me to think about the logic I should use and the algorithm I should use to solve such problems. It would be a great help for me if somebody can explain me about this.
Thank You.