[Java] DFS + Memo
\nclass Solution {\n    static int[][] dirs = {{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, in
```\nclass Solution {\n    static int[][] dirs = {{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        return dfs(K,r,c,N,new HashMap<>());\n    }\n    \n    double dfs(int K, int i, int j, int N, Map<String,Double> dp){\n\n        if(i < 0 || j < 0 || i >= N || j >= N)\n            return 0.0;\n        if(K == 0)\n            return 1.0;\n        double result = 0.0;\n        String position = i + "," + j +  "," + K;\n        if(dp.get(position) != null)\n            return dp.get(position);\n        for(int[] dir : dirs)\n            result += dfs(K-1, i+dir[0], j+dir[1], N, dp);\n        \n        dp.put(position,result * 0.125);\n        return dp.get(position);\n\n    }\n}\n```
[]