Place tiles horizentally or vertically
dp [ i ] = Math . Max ( dp [ i - 1 ] + Math . Abs ( grid [ 0 , i - 1 ] - grid [ 1 , i - 1 ] ) , dp [ i - 2 ] + Math . Abs ( grid [ 0 , i - 2 ] - grid [ 0 , i - 1 ] ) + Math . Abs ( grid [ 1 , i - 2 ] - grid [ 1 , i - 1 ] ) ) ; }