Very Easy || 100% || Fully Explained || Java || C++
Java Solution:\n\nclass Solution {\n    public double knightProbability(int n, int k, int row, int column) {\n        int[][] dir = {{-2, -1}, {-1, -2}, {1, -2}
# **Java Solution:**\n```\nclass Solution {\n    public double knightProbability(int n, int k, int row, int column) {\n        int[][] dir = {{-2, -1}, {-1, -2}, {1, -2}, {2, -1}, {2, 1}, {1, 2}, {-1, 2}, {-2, 1}};\n        // We use dynamic programming to store the probabilities at each cell for each move...\n        // The dp array is a 3-dimensional array...\n        // dp[i][r][c] represents the probability of the knight being at cell (r, c) after i moves...\n        double[][][] dp = new double[k + 1][n][n];\n        // At first, initialize dp[0][row][column] to 1.0, as the knight starts at the specified cell.\n        dp[0][row][column] = 1.0;\n        // For each move from 1 to k, the algorithm iterates over each cell on the chessboard.\n        for (int i = 1; i <= k; i++) {\n            // For each cell, it considers all 8 possible moves of the knight &\n            // Calculates the probability of reaching that cell from the neighboring cells.\n            for (int r = 0; r < n; r++) {\n                for (int c = 0; c < n; c++) {\n                    for (int[] d : dir) {\n                        // Introduce the terms newRow & newCol...\n                        int newRow = r + d[0];\n                        int newCol = c + d[1];\n                        // If the new cell is within the bounds of the chessboard....\n                        if (newRow >= 0 && newRow < n && newCol >= 0 && newCol < n) {\n                            // update by adding the probability of the previous move divided by 8.0...\n                            dp[i][r][c] += dp[i - 1][newRow][newCol] / 8.0;\n                        }\n                    }\n                }\n            }\n        }\n        // Initialize the output probability...\n        double output = 0.0;\n        // Sum up the output probabilities of all cells at the kth move to get the final output probability.\n        for (int r = 0; r < n; r++) {\n            for (int c = 0; c < n; c++) {\n                output += dp[k][r][c];\n            }\n        }\n        // return the output that the knight remains on the board after k moves.\n        return output;\n    }\n}\n```\n\n# **C++ Solution:**\n```\nclass Solution {\npublic:\n    double knightProbability(int n, int k, int row, int column) {\n        // We use dynamic programming to store the probabilities at each cell for each move...\n        // The dp array is a 3-dimensional array...\n        // dp represents the probability of the knight being at cell (r, c) after m moves...\n        vector<vector<double>> dp(n, vector<double>(n, 0));\n        vector<int> dr = {-2, -2, -1, -1, 1, 1, 2, 2};\n        vector<int> dc = {-1, 1, -2, 2, -2, 2, -1, 1};\n        // At first, initialize dp[0][row][column] to 1, as the knight starts at the specified cell.\n        dp[row][column] = 1;\n        // For each move from 1 to k, the algorithm iterates over each cell on the chessboard.\n        for (int m = 0; m < k; m++) {\n            vector<vector<double>> tmp(n, vector<double>(n, 0));\n            // For each cell, it considers all 8 possible moves of the knight &\n            // Calculates the probability of reaching that cell from the neighboring cells.\n            for (int r = 0; r < n; r++) {\n                for (int c = 0; c < n; c++) {\n                    for (int i = 0; i < 8; i++) {\n                        // Introduce the terms newRow & newCol...\n                        int newRow = r + dr[i];\n                        int newCol = c + dc[i];\n                        // If the new cell is within the bounds of the chessboard....\n                        if (newRow >= 0 && newRow < n && newCol >= 0 && newCol < n) {\n                            // update by adding the probability of the previous move divided by 8.0...\n                            tmp[newRow][newCol] += dp[r][c] / 8.0;\n                        }\n                    }\n                }\n            }\n            dp = tmp;\n        }\n        // Initialize the output probability...\n        double output = 0;\n        // Sum up the output probabilities of all cells at the kth move to get the final output probability.\n        for (int r = 0; r < n; r++) {\n            for (int c = 0; c < n; c++) {\n                output += dp[r][c];\n            }\n        }\n        // return the output that the knight remains on the board after k moves.\n        return output;\n    }\n};\n```\n**I am working hard for you guys...\nPlease upvote if you found any help with this code...**
['C', 'Java', 'JavaScript']