partial-derangement

Enumerating a set of permutations based on a condition

I've been able to solve the following problem using std::next_permutation (c++) etc, but I'm now thinking about it in a more general and would very much like to form an expression as this type of problem seems to lend itself - though I'm not having any luck as of yet. Here is the question: Given a running race with N contestants, wha...