Solution
C++ []\nclass Solution {\npublic:\n    double knightProbability(int n, int k, int row, int column) {\n        vector<vector<double>> dp(n, vector<double>(n, 0))
```C++ []\nclass Solution {\npublic:\n    double knightProbability(int n, int k, int row, int column) {\n        vector<vector<double>> dp(n, vector<double>(n, 0));\n        dp[row][column] = 1;\n        double temp;\n        int outside = 0;\n        for(int t= 0; t<k; t++){\n            vector<vector<double>> dp2(n, vector<double>(n,0));\n            for(int i = 0; i <n; i++){\n                for(int j = 0; j<n; j++){\n                    temp = dp[i][j];\n                    if(temp != 0){\n                        if(i-2 < 0){\n                            outside+=2*temp;\n                        }\n                        else{\n                            if(j-1 < 0){\n                                outside+=temp;\n                            }\n                            else{\n                                dp2[i-2][j-1]+=temp/8.0;\n                            }\n                            if(j+1 >= n){\n                                outside+=temp;\n                            }\n                            else{\n                                dp2[i-2][j+1]+=temp/8.0;\n                            }\n                        }\n                        if(j-2 < 0){\n                            outside+=2*temp;\n                        }\n                        else{\n                            if(i-1 < 0){\n                                outside+=temp;\n                            }\n                            else{\n                                dp2[i-1][j-2]+=temp/8.0;\n                            }\n                            if(i+1 >= n){\n                                outside+=temp;\n                            }\n                            else{\n                                dp2[i+1][j-2]+=temp/8.0;\n                            }\n                        }\n                        if(j+2 >= n){\n                            outside+=2*temp;\n                        }\n                        else{\n                            if(i-1 < 0){\n                                outside+=temp;\n                            }\n                            else{\n                                dp2[i-1][j+2]+=temp/8.0;\n                            }\n                            if(i+1 >= n){\n                                outside+=temp;\n                            }\n                            else{\n                                dp2[i+1][j+2]+=temp/8.0;\n                            }\n                        }\n                        if(i+2 >= n){\n                            outside+=2*temp;\n                        }\n                        else{\n                            if(j-1 < 0){\n                                outside+=temp;\n                            }\n                            else{\n                                dp2[i+2][j-1]+=temp/8.0;\n                            }\n                            if(j+1 >= n){\n                                outside+=temp;\n                            }\n                            else{\n                                dp2[i+2][j+1]+=temp/8.0;\n                            }\n                        }\n                    }           \n                }\n            }\n            dp = dp2;\n        }\n        double ans = 0.0;\n        for(int i = 0; i <n; i++){\n            for(int j = 0; j<n; j++){\n                ans += double(dp[i][j]);\n            }\n        }\n        return ans;\n    }\n};\n```\n\n```Python3 []\nclass Solution:\n    def knightProbability(self, n: int, k: int, row: int, column: int) -> float:\n        def next_pos(i, j):\n            dxdy = [(2, 1), (2, -1), (-2, 1), (-2, -1)]\n            dxdy.extend([(y,x) for x,y in dxdy])\n            res = [(i+dx, j+dy) for dx,dy in dxdy if i+dx >= 0 and j+dy >=0 and i+dx < n and j+dy < n]\n            return res\n        map_next = [[next_pos(i, j) for j in range(n)] for i in range(n)]\n        prob = [[0 for j in range(n)] for i in range(n)]\n        prob[row][column] = 1\n        for count in range(k):\n            prob2 = [[0 for j in range(n)] for i in range(n)]\n            for i in range(n):\n                for j in range(n):\n                    if prob[i][j] == 0:\n                        continue\n                    for i2, j2 in map_next[i][j]:\n                        prob2[i2][j2] += prob[i][j]/8\n            prob = prob2\n        return sum([sum(l) for l in prob])\n```\n\n```Java []\nclass Solution {\n    private final int[][] moves = {{2, 1}, {-2, 1}, {1, 2}, {-1, 2}, {2, -1}, {-2, -1}, {1, -2}, {-1, -2}};\n\n    public double knightProbability(int n, int k, int row, int column) {\n        double[][][] cache = new double[n / 2 + 1][n / 2 + 1][k + 1];\n        return solver(n, k, row, column, cache);\n    }\n    private double solver(int n, int k, int row, int column, double[][][] memo) {\n        if (row < 0 || row >= n || column < 0 || column >= n) return 0.0;\n        if (k == 0) return 1.0;\n\n        row = Math.min(row, n - 1 - row);\n        column = Math.min(column, n - 1 - column);\n\n        if (row < column) return solver(n, k, column, row, memo);\n        if (memo[row][column][k] != 0.0) return memo[row][column][k];\n\n        double probability = 0.0;\n        for (int[] move : moves) {\n            probability += solver(n, k - 1, row + move[0], column + move[1], memo) / 8.0;\n        }\n        memo[row][column][k] = probability;\n        return probability;\n    }\n}\n```\n
['C++', 'Java', 'Python3']