Java AC DP solution
\nclass Solution {\n    public double knightProbability(int N, int K, int r, int c) {\n        double[][] dp = new double[N][N];\n        double[][] dp2 = new d
```\nclass Solution {\n    public double knightProbability(int N, int K, int r, int c) {\n        double[][] dp = new double[N][N];\n        double[][] dp2 = new double[N][N];\n        double constaProb = 0.125;\n        int[][] moves = {{2,1},{2,-1},{-2,1},{-2,-1},{1,2},{1,-2},{-1,2},{-1,-2}};\n        dp[r][c] = 1.0;\n        double totProb = 1.0;\n        for (int k = 1; k <= K; k++) {\n            totProb = 0.0;\n            dp2 = new double[N][N];\n            for (int i = 0; i < N; i++) {\n                for (int j = 0; j < N; j++) {\n                    for (int move = 0; move < moves.length; move++) {\n                        int pr = i + moves[move][0];\n                        int pc = j + moves[move][1];\n                        if (pr < 0 || pc < 0 || pr >= N || pc >= N) {\n                            continue;\n                        }\n                        dp2[i][j] += constaProb * dp[pr][pc];\n                    }\n                    totProb += dp2[i][j];\n                }\n            }\n            dp = dp2;\n        }\n        return totProb;\n    }\n}\n```
[]