public int minSailCost(int[][] input) { // write code here row = input.length; col = input[0].length; int[][] dp = new int[row][col]; int fill = row * col * 2; for (int i = 0; i < row; i++) { Arrays.fill(dp[i], fill); } dp[0][0] = 0; hasVisited = new boolean[row][col]; hasVisited[0][0] = true; dfs(input, dp, 0, 0); return dp[row - 1][col - 1] == fill ? -1 : dp[row - 1][col - 1]; }