Java short and crisp | DFS with memorization.
\nclass Solution {\n    final int[] rows={2,2,1,1,-2,-2,-1,-1};\n    final int[] cols={1,-1,2,-2,1,-1,2,-2};\n    int size;\n    HashMap<String,Double> memo;\n 
```\nclass Solution {\n    final int[] rows={2,2,1,1,-2,-2,-1,-1};\n    final int[] cols={1,-1,2,-2,1,-1,2,-2};\n    int size;\n    HashMap<String,Double> memo;\n    private boolean isValid(int r,int c){\n        return r>=0 && r<size && c>=0 && c<size;\n    }\n    public double knightProbability(int N, int K, int r, int c) {\n        size=N;\n        memo=new HashMap();\n        return dfs(r,c,K);\n    }\n    private double dfs(int r,int c,int K){\n        if(K==0) return 1;\n        String key=r+" "+c+" "+K;\n        if(memo.containsKey(key)) return memo.get(key);\n        double res=0;\n        for(int i=0;i<8;i++){\n            int nr=r+rows[i];\n            int nc=c+cols[i];\n            if(isValid(nr,nc)) res+=(dfs(nr,nc,K-1)/8);\n        }\n        memo.put(key,res);\n        return res;\n    }\n}\n```
[]