public int longestIncreasingPath(int[][] m) {
        if (m == null || m.length == 0 || m[0].length == 0) return 0;

        int[][] dp = new int[m.length][m[0].length];
        int maxLen = 0;
        for (int i = 0; i < m.length; ++i) {
            for (int j = 0; j < m[0].length; ++j) {
                maxLen = Math.max(maxLen, dfs(m, dp, i, j));
            }
        }
        return maxLen;
    }