Top - down dp + bitmask
\n#define seto(x, i) memset(x, i, sizeof x)\n#define EB emplace_back \n#define PB push_back\n#define popcount __builtin_popcount\n#define clz __builtin_clz\n#de
```\n#define seto(x, i) memset(x, i, sizeof x)\n#define EB emplace_back \n#define PB push_back\n#define popcount __builtin_popcount\n#define clz __builtin_clz\n#define ctz __builtin_ctz\n#define parity __builtin_parity\ntypedef pair<int, int>PII;\ntypedef tuple<int, int, int>T3;\nclass Solution {\n    int dx[8] = {-2, -1, 1, 2, 2, 1, -1, -2};\n    int dy[8] = {1, 2, 2, 1, -1, -2, -2, -1};\n    const int N = 50;\npublic:\n    int maxMoves(int kx, int ky, vector<vector<int>>& positions)\n    {\n        positions.insert(positions.begin(), {kx, ky});\n        int n = positions.size();\n        vector<vector<vector<int>>>dist(n, vector<vector<int>>(N, vector<int>(N, INT_MAX)));\n        auto getD = [&](int ind)\n        {\n            int sx = positions[ind][0], sy = positions[ind][1];\n            int processed[N][N];\n            seto(processed, 0); \n            priority_queue<T3, vector<T3>, greater<T3>>pq;\n            pq.emplace(0, sx, sy);\n            dist[ind][sx][sy] = 0;\n            while(pq.size())\n            {\n                auto [d, i, j] = pq.top();\n                pq.pop();\n                if(processed[i][j])continue;\n                processed[i][j] = 1;\n                for(int k = 0; k < 8; k ++)\n                {\n                    int x = i + dx[k], y = j + dy[k];\n                    if(x < 0 || x >= N || y < 0 || y >= N)continue;\n                    if(dist[ind][x][y] > d + 1)\n                    {\n                        dist[ind][x][y] = d + 1;\n                        pq.emplace(dist[ind][x][y], x, y);\n                    }\n                }\n            }\n        };\n        for(int i = 0; i < n; i ++)\n        {\n            getD(i);\n        }\n        int m = 1 << n;\n        int total = m - 2; // ignore the knight at the begining\n        vector<vector<int>>memo(n, vector<int>(m, -1));\n        function<int(int, int)>dfs = [&](int i, int remain) -> int\n        {\n            if(!remain)return 0;\n            if(memo[i][remain] != -1)return memo[i][remain];\n            int turn = parity(total ^ remain);\n            int res = turn == 1 ? INT_MAX : 0;\n            if(!turn)//A\n            {\n                for(int j = 0; j < n; j ++)\n                {\n                    if(remain >> j & 1)\n                        res = max(dfs(j, remain ^ (1 << j)) + dist[j][positions[i][0]][positions[i][1]], res);\n                }\n            }else{\n                for(int j = 0; j < n; j ++)\n                {\n                    if(remain >> j & 1)\n                        res = min(dfs(j, remain ^ (1 << j)) + dist[j][positions[i][0]][positions[i][1]], res);\n                }\n            }\n            return memo[i][remain] = res;\n        };\n        return dfs(0, total);\n    }\n};\nauto init = []()\n{\n    ios_base::sync_with_stdio(0);\n    cin.tie(0);\n    cout.tie(0);\n    return nullptr;\n}();\n```
['Dynamic Programming', 'Bit Manipulation', 'Memoization', 'Bitmask', 'C++']