These are the 2D dynamic programming problems every placement candidate should be able to solve, from counting grid routes to a shortest round trip. Say what the table cell means first, then fill it in a safe order. Trace a small input by hand, then check your program against every test.