🏆C++ || DP (recursion + memoization)
Code\n\nclass Solution {\npublic:\n    double help(int r,int c,int n,int k,vector<vector<vector<double>>>&dp){\n        if(r<0 || c<0 || r>=n || c>=n)return 0;\
# Code\n```\nclass Solution {\npublic:\n    double help(int r,int c,int n,int k,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        int dx[8] = {2,2,-2,-2,1,1,-1,-1};\n        int dy[8] = {1,-1,1,-1,2,-2,2,-2};\n        double ans=0;\n       for(int i=0;i<8;i++){\n           ans += help(r+dx[i],c+dy[i],n,k-1,dp)/8;\n        }\n        return dp[r][c][k] = ans;\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 help(r,c,n,k,dp); \n    }\n};\n```\n![upvote (2).jpg](https://assets.leetcode.com/users/images/a0956370-8756-451a-921c-c15188780c5f_1690006892.6314602.jpeg)\n
['Dynamic Programming', 'Recursion', 'Memoization', 'C++']