Your 'ways' function has some problems. For instance, if there are N students and just one task, your formula would yield N as result, however, since each of the N students have the same one task, the outcome should be 1.
A logical requirement would be that the tasks are as evenly distributed as possible (assuming all tasks have the same weight). For instance, if N = 5 and K = 3, then the distribution 1-1-1-2-3 should not be allowed. A simple strategy would be to distribute the K tasks over the first K students, then again the K tasks over the next K students, until all studens have been appointed a task. The number of possibilities would then be:
(to be disclosed)
In your example, we have that N = 3, K = 2, and you give 6 possibilities. According to the undisclosed formula above, I would get 4 possibilities (1-2-1, 1-2-2, 2-1-1, 2-1-2). Which of the possibilities that you give do I drop?
But if the only requirement is that all tasks should be appointed at least once, then the question of how many combinations are possible is really interesting!
PS: what is factorial(0)?
It's fun to be me, and still legal in 9 states! Wanna see my tiny ad?
Create Edit Print & Convert PDF Using Free API with Java