Easy To Understand || C++
\n\n# Code\ncpp []\nclass Solution {\npublic:\n    int maxMoves(int kx, int ky, vector<vector<int>>& pos) {\n        int dx[8] = {2, 2, -2, -2, 1, 1, -1, -1};\n
\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int maxMoves(int kx, int ky, vector<vector<int>>& pos) {\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        int n = pos.size();\n        int dp[n + 1][n + 1];\n        int X, Y;\n        int dist[55][55];\n        function<void(int, int)> give_min_dist = [&](int x, int y) {\n            queue<pair<int, pair<int, int>>> q;\n            q.push({0, {x, y}});\n\n           \n            dist[x][y] = 0;\n\n            while (!q.empty()) {\n                auto par = q.front();\n                q.pop();\n                if (dist[par.second.first][par.second.second] != par.first)\n                    continue;\n                for (int i = 0; i < 8; i++) {\n                    int new_x = par.second.first + dx[i];\n                    int new_y = par.second.second + dy[i];\n                    if (new_x >= 0 && new_x <= 50 && new_y >= 0 &&\n                        new_y <= 50) {\n\n                        int new_d = par.first + 1;\n                        if (new_d < dist[new_x][new_y]) {\n                            dist[new_x][new_y] =\n                                dist[par.second.first][par.second.second] + 1;\n                            q.push({new_d, {new_x, new_y}});\n                        }\n                    }\n                }\n            }\n        };\n  \n\n        for (int i = 0; i < n; i++) {\n\n            memset(dist, 100, sizeof(dist));\n            give_min_dist(pos[i][0], pos[i][1]);\n            for (int j = 0; j < n; j++) {\n                dp[i][j] = dist[pos[j][0]][pos[j][1]];\n               \n            }\n          \n        }\n\n        int kdist[n];\n        memset(dist, 100, sizeof(dist));\n        give_min_dist(kx, ky);\n       \n        for (int i = 0; i < n; i++) {\n\n            kdist[i] = dist[pos[i][0]][pos[i][1]];\n           \n        }\n   \n        int memo[65536][15][2];\n        function<int(int, int, int)> fun = [&](int mask, int ind, int turn) {\n            if (mask == (1 << (n)) - 1) {\n                return 0;\n            }\n\n            if (memo[mask][ind][turn] != -1)\n                return memo[mask][ind][turn];\n            int ans = 0;\n            if (mask == 0) {\n                for (int i = 0; i < n; i++) {\n                    ans =\n                        max(ans, fun(mask + (1 << i), i, 1 - turn) + kdist[i]);\n                }\n                memo[mask][ind][turn] = ans;\n                return ans;\n            }\n\n            else {\n                if (turn) {\n                    ans = INT_MAX;\n                    for (int i = 0; i < n; i++) {\n                        if (((mask >> i) & 1) || i == ind)\n                            continue;\n                        ans = min({ans, fun(mask + (1 << i), i, 1 - turn) +\n                                            dp[ind][i]});\n                    }\n                     memo[mask][ind][turn] = ans;\n                     return ans;\n                }\n                else {\n                    ans = INT_MIN;\n                    for (int i = 0; i < n; i++) {\n                        if (((mask >> i) & 1) || i == ind)\n                            continue;\n                        ans = max({ans, fun(mask + (1 << i), i, 1 - turn) +\n                                            dp[ind][i]});\n                    }\n                     memo[mask][ind][turn] = ans;\n                     return ans;\n                }\n            }\n           \n        };\n        memset(memo, -1, sizeof(memo));\n        return fun(0, 0, 0);\n    }\n};\n```
['Array', 'Dynamic Programming', 'Breadth-First Search', 'Bitmask', 'C++']