ACM Midatlantic programming contest 2014, Problem G Pings in the ocean, probes, probabilities. Thoughts: Dynamic programming Let P(x,y) be the probability of being undetected at position (x,y). G(k, x, y) is the highest probability of being undetected at position (x,y) if arriving there on the k-th steps. Basic idea G(k+1,x,y) = P(x,y)*max(G(k,x-1,y), G(k,x+1,y), G(k,x,y-1), G(k,x,y+1)). Boundary conditions: G(0,0,y) = P(0,y). G(0,x,y) = 0, if x > 0. G(k,x,y) = 0, if x or y is out of bounds. Use caching (memoizing), or move on to full dynamic programming.