BFS + DFS
We first determine the minimum moves between the knight and pawns, and between each pair of pawns.\n\nWe can use BFS for that.\n\nThen, we run DFS starting from
We first determine the minimum moves between the knight and pawns, and between each pair of pawns.\n\nWe can use BFS for that.\n\nThen, we run DFS starting from the knight:\n- We track "captured" pawns using a bitmask `mask`.\n- For each turn, we "capture" one of remaining pawns and contine with DFS.\n- For Alice\'s turns, we maximize the result, and for Bob\'s - minimize.\n\nTo avoid recomputations, we memoise DFS results in `dp` for each `mask` and the knigh position `i`.\n**C++**\n```cpp\nint moves[17][17], dp[17][32767] = {};\nint knight[9] = {1, 2, 1, -2, -1, 2, -1, -2, 1}; \nvoid bfs(int i, vector<vector<int>> &pos) {\n    int b[50][50] = {}, sx = pos[i][0], sy = pos[i][1];\n    vector<pair<int, int>> q{{sx, sy}};\n    while (!q.empty()) {\n        vector<pair<int, int>> q1;\n        for (auto [x, y] : q)\n            for (int d = 0; d + 1 < 9; ++d) {\n                int dx = x + knight[d], dy = y + knight[d + 1];\n                if (min(dx, dy) >= 0 && max(dx, dy) < 50 && !(dx == sx && dy == sy) && b[dx][dy] == 0) {\n                    b[dx][dy] = b[x][y] + 1;\n                    q1.push_back({dx, dy});\n                }\n            }\n        swap(q, q1);\n    }\n    for (int j = i + 1; j < pos.size(); ++j)\n        moves[i][j] = moves[j][i] = b[pos[j][0]][pos[j][1]];        \n}\nint dfs(int i, unsigned int mask, int turns, int sz) {\n    if (turns == sz)\n        return 0;\n    if (dp[i][mask] == 0) {\n        dp[i][mask] = turns % 2 ? INT_MAX : 0;\n        for (int j = 0; j < sz; ++j)\n            if (((1 << j) & mask) == 0) {\n                int resj = moves[i][j] + dfs(j, mask + ((1 << j)), turns + 1, sz);\n                dp[i][mask] = turns % 2 ?  min(dp[i][mask], resj) : max(dp[i][mask], resj);\n            }\n    }\n    return dp[i][mask];\n}\nint maxMoves(int kx, int ky, vector<vector<int>>& positions) {\n    positions.push_back({kx, ky});\n    for (int i = 0; i < positions.size(); ++i)\n        bfs(i, positions);\n    return dfs(positions.size() - 1, 0, 0, positions.size() - 1);\n}\n```
['C']