closed-form or recursion solution to combinatorial couting? Mr. Fushi is now working in a telecom company in Paris, responsible for generating the daily assignment of technicians to particular tasks, such as repairing and installation procedures. In principle, every technician can do every task but for timing reasons, he can only perform a fixed number of tasks per day. For regulamentation reasons, each task requires a fixed number of technicians.
The following picture shows a possible assignment of 4 technicians to 4 tasks, with the requirement that two technicians must be assigned to each task and each technician must perform two tasks.
Josh    1, 4    
Bruce   1, 2                    
Newton  2, 3
Curie   3, 4 

Since there may be different possible assignments, Mr. Fushi would like to show all possibilities to the director so that he can choose the best assignment. However, there may be too many and, in that case, Mr. Fushi has to choose a sample of it. For that reason, Mr. Fushi needs to count how many possible assignments exist. Could you help him?
Given the number of technicians (M), the number of tasks (N), the required number of tasks per technician (P) and the required number of technicians per task (Q) find the number of all distinct assignments. 
For example, for M = 6, N = 6, Q = 1 and P = 1 the solution is 720.
For M = 6, N = 6, Q = 2 and P = 2 the solution is 67950.
Is there a closed-form solution to this problem? If not how is this solvable? Maybe with recursion?
I've come to conclusion that the condition P * M == N * Q must be met for the solution to be > 0. Am I right?
 A: The teacher that assigned this graded homework also denoted that he couldn't conceive of an immediate formula nor was he certain that one even existed for all cases (∀ M, N, P, Q). 
A solution:
You should start off with a recursive function which makes every possible combination; those that assigning Q technicians to the N Tasks whilst every technician having P distinct tasks assigned to him are considered valid.
When this is done you can ponder on how backtracking would be ever so helpful in discarding redundant or repetitive calls but, alas, it's not that obvious how you can infer that you've arrived at that combination already. So in order to make the most of memoization you could perhaps transform the combination (number of technicians in each task or number of tasks each technician has) into an unique number (perhaps an already implemented hashtable, counting the numbers that make up this combination or even treating it as a whole number in base Q).
This will greatly cut down your time, from years to fractions of a second. For instance, one of the case tests will generate around 10^7 combinations and your final answer should be able to deal with that and more in less than 0.5 seconds ;-)
A: This is a partial answer. Assume $M=N$. 
Suppose $Q=P=1$. The number of distinct assignments should be $M!$, since anyone can have any task and no task is repeated.
Suppose $Q=P=2$. Distribute tasks 1 through $M$ as before. We now want to distribute these tasks again, but we don't want anyone to get the same task as before. This is the same as finding a derangement of $\{1, 2, \dots, M\}$. This can be done in $\left[\frac{n!}{e}\right]$ ways, where the $[~~]$ denotes rounding to the nearest integer. The order that the jobs are received doesn't matter, so we divide by 2. Then the number of distinct arrangements should be $\frac{M!}{2} \cdot \left[\frac{n!}{e}\right]$. 
When $M=6$, this gives 95400, which is not the same as the answer that you provided. The mistake could be mine, but where did your answer come from?
