Figure illustration of DP process
Illustration with figure:\n\nLet\'s begin with an example: \nN = 3;\nmines = {{0, 1}, {2,1}}\nWith the above information, you can easily get the input matrix: g
Illustration with figure:\n\nLet\'s begin with an example: \nN = 3;\nmines = {{0, 1}, {2,1}}\nWith the above information, you can easily get the input matrix: grid\n![image](https://assets.leetcode.com/users/codedayday/image_1588718965.png)\n\nBy searching along 4 directions, you will get 4 sub matrix.\nBy combining them, you can get final dp, from which you can search matrix value as returned answer.\n\n\n\n```\nclass Solution {\npublic:\n    int orderOfLargestPlusSign(int N, vector<vector<int>>& mines) {\n        vector<vector<int>> dp(N, vector<int>(N, N));\n        for(auto& e: mines)  dp[e[0]][e[1]] = 0;\n        for(int i = 0; i < N; i++)\n            for(int j = 0, k = N - 1, u = 0, d = 0, l = 0, r =0; j < N; j++,k--){\n                dp[i][j] = min(dp[i][j], l = dp[i][j]  ?  l + 1 : 0 ); // from left, Note1\n                dp[j][i] = min(dp[j][i], u = dp[j][i] ?  u + 1 : 0); // from up/top\n                dp[i][k] = min(dp[i][k], r = dp[i][k] ? r + 1 : 0); // from right\n                dp[k][i] = min(dp[k][i], d = dp[k][i]? d + 1 : 0); // from down/bottom\n            }\n        \n        int ans = 0;\n        //for(auto& row: dp) for(auto e: row) ans = max(ans, e); //ok\n        for(int i = 0; i < N * N; i++) ans = max(ans, dp[i / N] [i % N]);\n        return ans;\n    }\n};\nNote1:\ndp[i][j]: how many continous 1 are in the immediate left of location [i,j]\n\n```
[]