“the total distance moved by all pegs should be kept at least”
If I am missing something, this is not a problem.
Since the binding order must be supported, you can simply copy the bindings 1, 2, 3, ...
+ - 1234 - + - + --- + --- 5 - + ------ + - + - 678 + 9 - + ------- 10 - + ----- 11-12 - + - 13
and the final state should be binding 1 in slot 1, pin 2 in slot 2, etc.
+ - 1 - + - 2 - + - 3 - + - 4 - + - 5 - + - 6 - + - 7 - + - 8 - + - 9 - + - 10 - + - 11 - + - 12 - + - 13 - +
The inability to jump the pins against each other does not matter, each binding should move at a certain distance from it, starting from its end point. As long as all the moves are in the right direction, and the binding never has to back up , then the distance that each individual binding should move is a simple constant (it does not depend on the order of the moves), and the sum of these distances, your cost function is also constant.
I do not see the need for dynamic programming or the problem of optimizing linear programming.
If you enter a cost for selecting a binding and set it, then perhaps there is a problem of optimization, but even this can be trivial.
Change in response to 1800 Information Comment
This is true only if the number of slots is equal to the number of pegs - this was not assumed in the problem expression - 1800 INFORMATION (2 hours ago)
Ok, I missed it. Thank you for pointing out that I am missing. I'm still not sure if this is rocket science.
Suppose # pegs> # hole. Calculate the final state as above, as if you had extra holes; then select N pegs that were moved on and remove them from the problem: those that are not moving. Reprogram, ignoring these bindings.
Assume # hole> # pegs. The correct final state may or may not have spaces. Calculate the final state as described above and see where the neighboring snaps have moved to each other. These are the moments where you can break it down into subtasks that can be solved trivially. There is another variable when you have holes at both ends of the adjacent subtask - where the final continuous sequence begins.
Yes, this is a little more complicated than I thought at first, but still it seems that a little work with pencil and paper should show that the solution is a couple of understandable and encoded cycles.