C++ || Memoized with all kindness
```\n\n\n\n\n  Trying since 4 hours but didn\'t get the expected output will definitely post the first (Commented ) approach soon   for now its upto memoization
```\n\n\n\n\n  Trying since 4 hours but didn\'t get the expected output will definitely post the first (Commented ) approach soon   for now its upto memoization working on direction array  \n  \n  \n  \n\n\nclass Solution {\npublic:\n    \n//     bool isValid(int ni,int nj,int n){\n//         if(ni>=0 && nj>=0 &&ni<n&&nj<n){\n//             return true;\n//         }\n//         else{\n//             return false;\n//         }\n//     }\n//     double knightProbability(int N, int K, int r, int c) {\n     \n//         if(K==0) return 1.0;\n        \n//         // parent chess board\n//         vector<vector<double>> parentBoard(N,vector<double>(N,0.0));\n        \n//         // child chess board\n//         vector<vector<double>> childBoard(N,vector<double>(N,0.0));\n        \n//         // row and col offset for generating next move or child positions\n//         // int rowoffset[] = {-2,-2,-1,-1,2,2,1,1};\n//         // int coloffset[] = {1,-1,2,-2,1,-1,2,-2};\n        \n        \n        \n//         // initial position probability 1\n//         parentBoard[r][c] = 1.0;\n        \n//         // Run K steps\n//         // Each step update the child position probability from parent position \n//         // After each step assign child as parent board and create new child board\n//         for(int m=1;m<=K;m++)\n//         {\n//             for(int i=0;i<N;i++)\n//             {\n//                 for(int j=0;j<N;j++)\n//                 { \n//                                         if(parentBoard[i][j]!=0){\n//                    int ni=i-2;\n//                    int nj=j+1;\n//         if(isValid(ni,nj,N)){\n//                         childBoard[ni][nj]+=parentBoard[i][j]/8.0;\n//                     }\n                    \n//                       ni=i-1;\n//                    nj=j+2;\n//                     if(isValid(ni,nj,N)){\n//                         childBoard[ni][nj]+=parentBoard[i][j]/8.0;\n//                     }\n                    \n//                      ni=i+1;\n//                    nj=j+2;\n                    \n//                      if(isValid(ni,nj,N)){\n//                         childBoard[ni][nj]+=parentBoard[i][j]/8.0;\n//                     }\n                    \n                    \n//                      ni=i+2;\n//                    nj=j-1;\n                    \n//                      if(isValid(ni,nj,N)){\n//                         childBoard[ni][nj]+=parentBoard[i][j]/8.0;\n//                     }\n//                       ni=i-2;\n//                     nj=j-1;\n                    \n//                      if(isValid(ni,nj,N)){\n//                         childBoard[ni][nj]+=parentBoard[i][j]/8.0;\n//                     }\n//                      ni=i+1;\n//                     nj=j-2;\n//                      if(isValid(ni,nj,N)){\n//                         childBoard[ni][nj]+=parentBoard[i][j]/8.0;\n//                     }\n                    \n                    \n//                       ni=i-1;\n//                     nj=j-2;\n//                      if(isValid(ni,nj,N)){\n//                         childBoard[ni][nj]+=parentBoard[i][j]/8.0;\n//                     }\n                    \n//                       ni=i-2;\n//                     nj=j-1;\n//                      if(isValid(ni,nj,N)){\n//                         childBoard[ni][nj]+=parentBoard[i][j]/8.0;\n//                     }\n                                      \n//                 }}\n//             }\n            \n//             parentBoard = childBoard;\n//             fill(childBoard.begin(),childBoard.end(),vector<double>(N,0.0));\n//         }\n        \n\n        \n//         double knightProb = 0.0;\n        \n//         // Loop through parent board after K steps and sum up all probability\n//         for(int i=0;i<N;i++){\n//             for(int j=0;j<N;j++){\n//                    knightProb+=parentBoard[i][j];\n//             }}\n//         return knightProb;\n     \n    \n        \n    \n   \n    \n    \n  double ego_(int N, int K, int r, int c, vector<vector<vector<double>>> & dp){   \n     if(r < 0 || c < 0 || r >= N || c >= N) return 0;\n        if(K == 0) return 1;\n        if(dp[r][c][K] != -1) return dp[r][c][K];\n        double sum = ego_(N, K - 1, r - 2, c - 1, dp) +\n                     ego_(N, K - 1, r - 1, c - 2, dp) +\n                     ego_(N, K - 1, r + 1, c - 2, dp) +\n                     ego_(N, K - 1, r + 2, c - 1, dp) +\n                     ego_(N, K - 1, r - 2, c + 1, dp) +\n                     ego_(N, K - 1, r - 1, c + 2, dp) +\n                     ego_(N, K - 1, r + 1, c + 2, dp) +\n                     ego_(N, K - 1, r + 2, c + 1, dp);\n        sum = sum / 8;\n        dp[r][c][K] = sum;\n        return dp[r][c][K];\n    \n    }\n    double knightProbability(int N, int K, int r, int c) {\n        vector<vector<vector<double>>> dp(N + 1, vector<vector<double>> (N + 1, vector<double>(K + 1, -1)));\n        return ego_(N, K, r, c, dp);\n    }\n    \n    \n    \n    \n    \n      \n        \n    \n};\n\n
['C++']