C# DP Solution with explanations (beats 100%)
We start by creating a matrix with probabilities of knight\'s survival till the appropriate turn for each cell. On the turn 0 it will contain only 1\'s as it\'s
We start by creating a matrix with probabilities of knight\'s survival till the appropriate turn for each cell. On the turn 0 it will contain only 1\'s as it\'s not possible for the knight to die without moving.\n```\n1 1 1 1\n1 1 1 1\n1 1 1 1\n1 1 1 1\n```\nWhen a knight makes a turn he can either run out of the board (hence the probability of his survival will be 0) or step on a cell for which we already counted the probability of his survival for the previous turn. We add upp the probabilities of his survival for each direction and divide them by 8 (total amount of directions), receiving the probability of surviving for the specified cell on the current turn.\n\nMatrix for turn 1:\n```\n0.25 0.375 0.375 0.25 \n0.375 0.5 0.5 0.375 \n0.375 0.5 0.5 0.375 \n0.25 0.375 0.375 0.25 \n```\n\nAs you can see, there is 0.25 chance to survive starting in the corner after making one turn as there are 2 cells ((1, 2) and (2, 1)) with probability of survival equal to 1 and 6 cells out of the borders.\n\nIf we want to count a probability for, say, cell (0, 1) for the turn 2 we find all possible places where a knight can step: (2, 0), (2, 2), (1, 3), sum up all probabilities of surviving and divide by 8.\n(0.375 + 0.5 + 0.375) / 8 = 0.15625\n\nLet\'s see the matrix for the next turn:\n```\n0.125 0.15625 0.15625 0.125 \n0.15625 0.15625 0.15625 0.15625 \n0.15625 0.15625 0.15625 0.15625 \n0.125 0.15625 0.15625 0.125 \n```\nAs you can see, the approprivate value is 0.15625 as we counted previously. Each time we create a new map for probabilities of current turn and in the end of turn we set the map for previous turn to the one we created recently.\n\nAs an optimization for this, we don\'t need to count every cell each time. It\'s obvious that probabilities for symmetric cells are the same, i.e. for each corner of the board. So we can count only 1/4 of the cells and then mirror them to the rest of the board. Here are the cells that we are processing each time:\n```\n1 1 1 0\n0 1 0 0\n0 0 0 0\n0 0 0 0\n```\n\nFor the 5-size matrix:\n```\n1 1 1 1 0\n0 1 1 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0\n```\nAll other cells values are being copied from these.\n\nAfter we process the board K times we just take the value from appropriate cell in the array and it will be the probability of the knight\'s survival.\n\nCode:\n\n```\npublic class Solution {\n    public double KnightProbability(int N, int K, int r, int c) {\n        var prob = new double[N, N];\n        for(var i = 0; i < N; i++)\n            for(var j = 0; j < N; j++)\n                prob[i, j] = 1d;\n        \n        var newprob = new double[N, N];\n        \n        var directions = new int[,] {{1, 2}, {-1, 2}, {-2, 1}, {-2, -1}, {-1, -2}, {1, -2}, {2, -1}, {2, 1}};\n        \n\t// Change the matrix K times\n        for(var iterator = 0; iterator < K; iterator++) {\n            for(var y = 0; y < Math.Ceiling((double) N / 2); y++) {\n                for(var x = y; x == y || x < N - y - 1; x++) {\n                    double sum = 0;\n\t\t    // Count probability for each direction\n                    for(var j = 0; j < directions.GetLength(0); j++)\n                        sum += Prob(prob, y + directions[j, 0], x + directions[j, 1]);\n\n                    sum /= 8;\n\t\t\t\t\t\t\t\t\t\t\n\t            // Mirror probability to 3 other sides of the matrix\n                    newprob[y, x] = sum;\n                    newprob[N - x - 1, y] = sum;\n                    newprob[x, N - y - 1] = sum;\n                    newprob[N - y - 1, N - x - 1] = sum;\n                }\n            }\n\n            prob = newprob;\n            newprob = new double[N, N];\n        }\n        \n        return prob[r, c];\n    }\n    \n    private double Prob(double[,] prob, int y, int x) {\n        if(y < 0 || x < 0 || y >= prob.GetLength(0) || x >= prob.GetLength(1))\n            return 0;\n        \n        return prob[y, x];\n    }\n}\n```
[]