public int dfs(int[][] nums, int[][] dp, int i, int j) {
        if (dp[i][j] > 0)
            return dp[i][j];
        int val = nums[i][j];
        int[] vals = new int[4];
        if (j - 1 >= 0 && nums[i][j - 1] > val)
            vals[0] = dfs(nums, dp, i, j - 1);
        if (j + 1 < nums[0].length && nums[i][j + 1] > val)
            vals[1] = dfs(nums, dp, i, j + 1);
        if (i - 1 >= 0 && nums[i - 1][j] > val)
            vals[2] = dfs(nums, dp, i - 1, j);
        if (i + 1 < nums.length && nums[i + 1][j] > val)
            vals[3] = dfs(nums, dp, i + 1, j);
        dp[i][j] = 1 + Math.max(vals[0], Math.max(vals[1], Math.max(vals[2], vals[3])));
        max = Math.max(dp[i][j], max);
        return dp[i][j];
    }