Simple Java DP solution with explanation
The first solution uses O(k*n^2) space for simplicity:\nAt every k and position i j we store the probability that the knight landed at position i j at step k.  
The first solution uses O(k*n^2) space for simplicity:\nAt every k and position i j we store the probability that the knight landed at position i j at step k.  We know that this probability is the sum of probabilities of the 8 directions in the previous step k-1 because in the previous step all 8 of those knight\'s have a chance of moving here.  For example since one of the directions is 2, 1 we take the current i-2 and j-1 and add that probability/8.0 (because if the knight is currently at i-2, j-1 the chance is only /8.0 that he\'ll choose this direction out of his 7 other choices).  \nWe initialize the r , c index of the k==0 board to 1, because at step 0, we already have the knight at position r, c so the chance it lands there in 0 steps is 100%.\nThe result is the sum of probabilities in all areas of the board in the Kth index Board.\n```\nclass Solution {\n    int [][] direction =new int[][]{{2,1},{-2,1},{2,-1},{-2,-1},{1,2},{1,-2},{-1,2},{-1,-2}};\n   \n    public double knightProbability(int N, int K, int r, int c) {\n        double [][][] ways = new double[K+1][N][N];\n        ways[0][r][c]=1;\n        for(int k=1; k<=K;++k){\n            for(int i=0; i<N;++i){\n                for(int j=0; j<N;++j){\n                    for(int [] dir: direction){\n                        int oldR = i-dir[0];\n                        int oldC = j-dir[1];\n                        if(oldR>=0 && oldC>=0 && oldR<N && oldC<N){\n                            ways[k][i][j]+=(ways[k-1][oldR][oldC]/8.0);\n                        }\n                    }\n                }\n            }\n        }\n        double res = 0;\n        for(int i=0; i<N;++i){\n            for(int j=0; j<N;++j){\n                res+=ways[K][i][j];\n            }\n        }\n        return res;\n    }\n}\n```\nbecause we only use the k and k-1 at every step we can just make the new Kth board be a variable and set the previous one to a previous variable, reducing the space to O(n^2):\n```\nclass Solution {\n    int [][] direction =new int[][]{{2,1},{-2,1},{2,-1},{-2,-1},{1,2},{1,-2},{-1,2},{-1,-2}};\n   \n    public double knightProbability(int N, int K, int r, int c) {\n        double [][] prevWays = new double[N][N];\n        prevWays[r][c]=1;\n        double res = 0;\n        for(int k=1; k<=K;++k){\n            double [][] ways = new double[N][N];\n            for(int i=0; i<N;++i){\n                for(int j=0; j<N;++j){\n                    for(int [] dir: direction){\n                        int oldR = i-dir[0];\n                        int oldC = j-dir[1];\n                        if(oldR>=0 && oldC>=0 && oldR<N && oldC<N){\n                            ways[i][j]+=(prevWays[oldR][oldC]/8.0);\n                        }\n                    }\n                }\n            }\n            prevWays=ways;\n        }\n        for(int i=0; i<N;++i){\n            for(int j=0; j<N;++j){\n                res+=prevWays[i][j];\n            }\n        }\n        return res;\n    }\n}\n```
[]