classSolution { funcherryPickup(grid: Array<IntArray>): Int { val dp = Array(grid.size) { Array(grid[0].size) { IntArray(grid[0].size) { Int.MIN_VALUE } } } val direction = arrayOf( intArrayOf(0, 0), intArrayOf(1, 0), intArrayOf(0, 1), intArrayOf(1, 1), intArrayOf(-1, 0), intArrayOf(0, -1), intArrayOf(-1, -1), intArrayOf(1, -1), intArrayOf(-1, 1) ) var max = Int.MIN_VALUE dp[0][0][grid[0].size - 1] = grid[0][0] + grid[0][grid[0].size - 1]
for (row in0 until grid.size - 1) { for (a in0 until grid[row].size) { for (b in0 until grid[row].size) { if (dp[row][a][b] == Int.MIN_VALUE) { continue }
for (dir in direction) { val aNext = a + dir[0] val bNext = b + dir[1]