Easy To understand Code. BFS + DP bitmasking(Only Memoization)
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nconst int N = 50;\nint knightMoves[8][2] = {{2, 1}, {2, -1}, {-2, 1}, {-2, -1},\n                         {1, 2}, {1, -2}, {-1, 2}, {-1, -2}};\n\nbool isInsideBoard(int x, int y) {\n    return (x >= 0 && x < N && y >= 0 && y < N);\n}\nvector<vector<int>> precomputeDistances(const vector<pair<int, int>>& positions) {\n    int n = positions.size();\n    vector<vector<int>> dist(n, vector<int>(n, -1));\n\n    for (int i = 0; i < n; ++i) {\n        queue<pair<pair<int, int>, int>> q;\n        vector<vector<bool>> visited(N, vector<bool>(N, false));\n\n        auto knightPos = positions[i];\n        q.push({knightPos, 0});\n        visited[knightPos.first][knightPos.second] = true;\n\n        while (!q.empty()) {\n            auto current = q.front();\n            q.pop();\n            int x = current.first.first;\n            int y = current.first.second;\n            int distance = current.second;\n\n            for (int j = 0; j < n; ++j) {\n                auto pawnPos = positions[j];\n                if (x == pawnPos.first && y == pawnPos.second) {\n                    dist[i][j] = distance;\n                }\n            }\n\n            for (int k = 0; k < 8; ++k) {\n                int nextX = x + knightMoves[k][0];\n                int nextY = y + knightMoves[k][1];\n\n                if (isInsideBoard(nextX, nextY) && !visited[nextX][nextY]) {\n                    visited[nextX][nextY] = true;\n                    q.push({{nextX, nextY}, distance + 1});\n                }\n            }\n        }\n    }\n\n    return dist;\n}\n\nclass Solution {\npublic:\n    int f(int mask, int idx, int n, bool alice, const vector<vector<int>>& dist, vector<vector<int>>& dp) {\n        if (mask == (1 << n) - 1) {\n            return 0; \n        }\n        if (dp[mask][idx] != -1) return dp[mask][idx];\n\n        int ans = (alice ? 0 : 1e9); \n        for (int i = 0; i < n; i++) {\n            if (mask & (1 << i)) continue; \n            int moves = dist[idx][i];\n            if (alice) {\n                ans = max(ans, moves + f(mask | (1 << i), i, n, 0, dist, dp));\n            } else {\n                ans = min(ans, moves + f(mask | (1 << i), i, n, 1, dist, dp));\n            }\n        }\n        return dp[mask][idx] = ans;\n    }\n\n    int maxMoves(int kx, int ky, vector<vector<int>>& p) {\n        int n = p.size();\n        vector<pair<int, int>> positions;\n        for (const auto& pos : p) {\n            positions.push_back({pos[0], pos[1]});\n        }\n        positions.push_back({kx, ky});\n        vector<vector<int>> dist = precomputeDistances(positions);\n        vector<vector<int>> dp(1 << n, vector<int>(n + 1, -1));\n        return f(0, n, n, 1, dist, dp);\n    }\n};\n```
['C++']