c++ solution
\nclass Solution {\npublic:\n    int n;\n    int dis[20][20];\n    int dp[16][(1<<16)+1];\n    vector<pair<int,int>>dir={{2,1},{2,-1},{-2,1},{-2,-1},{1,2},{1,-2
```\nclass Solution {\npublic:\n    int n;\n    int dis[20][20];\n    int dp[16][(1<<16)+1];\n    vector<pair<int,int>>dir={{2,1},{2,-1},{-2,1},{-2,-1},{1,2},{1,-2},{-1,2},{-1,-2}};\n    void bfs(int index,vector<vector<int>>&pos,int a,int b){\n        queue<pair<int,int>>q;\n        q.push({a,b});\n        vector<vector<int>>d(50,vector<int>(50,1e8));\n        d[a][b]=0;\n        while(q.size()){\n            auto [x,y]=q.front();\n            q.pop();\n            for(auto &it:dir){\n                int nx=x+it.first;\n                int ny=y+it.second;\n                if(nx>=0&&ny>=0&&nx<50&&ny<50&&d[nx][ny]>d[x][y]+1){\n                    d[nx][ny]=d[x][y]+1;\n                    q.push({nx,ny});\n                }\n            }\n        }\n        for(int i=0;i<n;i++){\n            dis[index][i]=d[pos[i][0]][pos[i][1]];\n        }\n    }\n    int find(vector<vector<int>>&nums,int index,int mask,int turn){\n        if(mask==((1<<n)-1)) return 0;\n        int ans=(turn)?-1e8:1e8;\n        if(dp[index][mask]!=-1) return dp[index][mask];\n        for(int i=0;i<nums.size();i++){\n            if(mask&(1<<i)) continue;\n            int value = dis[index][i];\n            if(turn){\n                ans=max(ans,value+find(nums,i,mask|(1<<i),turn^1));\n            }\n            else{\n                ans=min(ans,value+find(nums,i,mask|(1<<i),turn^1));\n            }\n        }\n        return dp[index][mask]= ans;\n    }\n    int maxMoves(int kx, int ky, vector<vector<int>>& pos) {\n        pos.insert(pos.begin(),{kx,ky});\n        memset(dp,-1,sizeof(dp));\n        n=pos.size();\n        for(int i=0;i<n;i++){\n            bfs(i,pos,pos[i][0],pos[i][1]);\n        }\n        return find(pos,0,1,1);\n    }\n};\n```
['C', 'C++']