My easy understand dp solution
java\nclass Solution {\n    private int[][] dirs = new int[][]{{1, 2}, {2, 1}, {2, -1}, {1, -2}, {-1, -2}, {-2, -1}, {-2, 1}, {-1, 2}};\n    public double knigh
```java\nclass Solution {\n    private int[][] dirs = new int[][]{{1, 2}, {2, 1}, {2, -1}, {1, -2}, {-1, -2}, {-2, -1}, {-2, 1}, {-1, 2}};\n    public double knightProbability(int N, int K, int r, int c) {\n        double[][][] dp = new double[K + 1][N][N];\n        dp[0][r][c] = 1;\n        for (int step = 1; step <= K; step++) {\n            for (int i = 0; i < N; i++) {\n                for (int j = 0; j < N; j++) {\n                    for (int[] dir : dirs) {\n                        int x = dir[0] + i;\n                        int y = dir[1] + j;\n                        if (x < 0 || x >= N || y < 0 || y >= N) continue;\n                        dp[step][i][j] += dp[step - 1][x][y] * 0.125;\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 += dp[K][i][j];\n            }\n        }\n        return res;\n    }\n}\n```
[]