DP with bitmask + BFS = cool problem, faster than 100% O(n ^ 2 * 2 ^ n)
cpp []\n    int processed[50][50];\n    int getMoves(int x1, int y1, int x2, int y2) {\n        const vector<pair<int, int>> offsets = {\n            pair{-2, 1
```cpp []\n    int processed[50][50];\n    int getMoves(int x1, int y1, int x2, int y2) {\n        const vector<pair<int, int>> offsets = {\n            pair{-2, 1}, {-1, 2}, {1, 2}, {2, 1},\n            {2, -1}, {1, -2}, {-1, -2}, {-2, -1}\n        };\n        memset(processed, 0, sizeof(processed));\n\n        queue<tuple<int, int, int>> q;\n        q.emplace(x1, y1, 0);\n        while (!empty(q)) {\n            const auto [i, j, d] = q.front();\n            q.pop();\n            if (i == x2 && j == y2) {\n                return d;\n            }\n            for (const auto& [a, b]: offsets) {\n                int x = i + a, y = j + b;\n                if (x < 0 || y < 0 || x >= 50 || y >= 50 || processed[x][y]) {\n                    continue;\n                }\n                q.emplace(x, y, d + 1);\n                processed[x][y] = true;\n            }\n        }\n        return -1;\n    }\n    \n    int maxMoves(int kx, int ky, vector<vector<int>>& positions) {\n        const int n = size(positions);\n        vector<vector<int>> dpMoves(n, vector<int>(n));\n        for (int i = 0; i < n; ++i) {\n            for (int j = 0; j < i; ++j) {\n                dpMoves[i][j] = dpMoves[j][i] = getMoves(positions[j][0], positions[j][1], positions[i][0], positions[i][1]);\n            }\n        }\n        \n\n        vector<vector<int>> dp(n, vector<int>(1 << n));\n        function<int(int, int)> getOrCompute;\n        getOrCompute = [&](int idx, int mask) {\n            if (dp[idx][mask]) {\n                return dp[idx][mask];\n            }\n            int movesDone = n - __builtin_popcount(mask);\n            if (movesDone == n) {\n                return 0;\n            }\n            bool maximise = movesDone % 2 == 0;\n            int res = maximise ? INT_MIN : INT_MAX;\n            for (int i = 0; i < n; ++i) {\n                if ((1 << i) & mask) {\n                    mask ^= (1 << i);\n                    int p = dpMoves[i][idx] + getOrCompute(i, mask);\n                    res = maximise ? max(res, p) : min(res, p);\n                    mask ^= (1 << i);\n                }\n            }\n            return dp[idx][mask] = res;\n        };\n        \n        int ans = 0;\n        for (int i = 0, mask =  pow(2, n) - 1; i < n; ++i) {\n            mask ^= (1 << i);\n            ans = max(ans, getMoves(kx, ky, positions[i][0], positions[i][1]) + getOrCompute(i, mask));\n            mask ^= (1 << i);\n        }\n        return ans;\n    }\n```
['C++']