I assume you know how to do it for one Knigt .
You can reformulate your problem as a linear program:
I will use the following notations :
We have N knights and N en locations.
xij = 1
if you chose knight i to go to location j and 0 otherwise
cij
is the min length of moving knight i to location j
Then you have the following linear program :
variables:
xij for i j in [0,N]
Cost function :
C= SUM(cij.xij for (i,j) in [0,N]x[0,N])
constraints:
SUM(xij for j in [1,N]) = 1 //exactly one knigt goes from i to j
SUM(xij for i in [1,N] ) = 1
(The matrix (xij) is a stochastic matrix)
if X is the matrix of (xij) you have n! possible matrix. This problem can be NP-Hard (there is no easy solution to this system, solving the system is pretty similar than testing all possible solutions).
EDIT:
This problem is called the assignment problem and there exist multiple algorithms to solve it in polynomial time . (check out @purav answer for an example)
As mentionned by @Purav even though this kind of problems can be NP-hard, in this case it can be solve in O(n^3)
About the problem @j_random_hacker raised :
Problem
If a knight is at a endpoint, the next knights should not be able to
go through this endpoint. So the Cij might need to be updated after
each knight is moved.
Remarks :
1. multiple optimal paths :
As there is no constraint on the side of the chessboard (ilimited chessboard), the order in which you do your move for achiveing the shortest path is not relevant, so there is always a lot a different shortest path (I won't do the combinatorics here).
Example with 2 knights
Let say you have 2 K and 2 endpoints ('x'), the optimal path are drawned.
-x
|
|
x
|
K-- --K
you move the right K to the first point (1 move) the second cannot use the optimal path.
-x
|
|
K
|
K-- --:
But I can easily create a new optimal path, instead of moving 2 right 1 up then 2 up 1 right.
1 can move 2 up 1 right the 1 up 2 right (just inverse)
--K
|
-
| K
| |
: --:
and any combination of path works :
1 U 2 R then 2 U 1 R etc... as long as I keep the same number of move
UP LEFT DOWN and RIGHT and that they are valid.
2. order in which knights are moved :
The second thing is that I can chose the order of my move.
example:
with the previous example if I chose to start with the left knight and go to the upper endpoint, dont have anymore endpoint constraint.
-K
|
|
x
|
:-- --K
-K
|
|
K
|
:-- --:
With these 2 remarks it might be possible to prove that there is no situation in which the lower bound calculated is not optimal .