[c++] BitMask DP + bfs
Let f(i,s) represent the maximum value that the knight can achieve when located at position i and facing the subset s .     The parity of siz[s] is the same as 
Let f(i,s) represent the maximum value that the knight can achieve when located at position i and facing the subset s .     The parity of siz[s] is the same as n:\n    f(i,s) = max{ g(k,s^k) + dist(i,k) }\n    f(i,0) = 0\n\nLet g(i,s) represent the minimum value that the knight can achieve when located at position i and facing the subset s. The parity of siz[s] is opposite to n:\n    g(i,s) = min{ f(k,s^k) + dist(i,k) }\n    g(i,0) = 0\n\t\n**code:**\n```\ntypedef pair<int,int>   pii;\nconst int               N   = 50;\n\nint dx[] = {-1,-1,-2,-2,1,1,2,2};\nint dy[] = {-2,2,-1,1,-2,2,-1,1};\n\nbool vis[N][N];\n\nbool check(int i, int j) { return 0<=i&&i<N&&0<=j&&j<N;   }; \n\nint bfs(vector<int>& S, vector<int>& T) {   \n    memset(vis, 0, sizeof(vis));\n\n    queue<pii>  que, tmp;\n    que.push({S[0],S[1]});\n    vis[S[0]][S[1]] = true;\n\n    for (int step = 1; !que.empty(); step++) {\n        while (!que.empty()) {\n            auto [x,y] = que.front(); que.pop();\n            int i, j;\n            for (int k = 0; k < 8; k++) if (check(i=x+dx[k],j=y+dy[k]) && !vis[i][j]) {\n                tmp.push({i,j});\n                vis[i][j] = true;\n                if (i == T[0] && j == T[1]) return step;\n            }\n        }\n        swap(que, tmp);\n    }\n\n    return 0x3f3f3f3f;\n}\n\n\nclass Solution {\npublic:\n    int maxMoves(int kx, int ky, vector<vector<int>>& a) {      int n = a.size();\n        a.push_back({kx,ky});\n\n        // prework:     Calculate the shortest paths between all points\n        int d[n+10][n+10];\n        memset(d, 0x3f, sizeof(d));\n        for (int i = 0; i <= n; i++) {     d[i][i] = 0; \n            for (int j = i+1; j <= n; j++) d[i][j] = d[j][i] = bfs(a[i], a[j]);\n        }\n\n\n        int f[n+10][(1<<n)+10]; memset(f, 0xcf, sizeof(f));\n        int g[n+10][(1<<n)+10]; memset(g, 0x3f, sizeof(g));\n\n        for (int i = 0; i <= n; i++) f[i][0] = g[i][0] = 0;\n        for (int s = 1; s < 1<<n; s++) {                    bool isDiff = (__builtin_popcount(s) ^ n) & 1;\n            for (int i = 0; i <= n; i++) if (!(s>>i&1)) {\n                for (int k = 0; k < n; k++) if (s>>k&1) {\n                    if (isDiff) g[i][s] = min(g[i][s], f[k][s^(1<<k)] + d[i][k]);\n                    else        f[i][s] = max(f[i][s], g[k][s^(1<<k)] + d[i][k]);\n                }\n            }\n        }\n\n        return f[n][(1<<n)-1];\n    }\n};\n\n```
[]