You have an equal number of cups and balls, each labelled from one to N. You randomly place one ball in each cup. Determine the number of possible combinations such that no balls are in the cup with a matching number. For example, if you have three balls and three cups, there are two valid solutions:
- 2, 3, 1
- 3, 1, 2
The following permutations do not meet the criteria for the reasons listed:
- 1, 2, 3 (all three balls are in the correct cups)
- 1, 3, 2 (ball 1 is in cup 1)
- 3, 2, 1 (ball 2 is in cup 2)
- 2, 1, 3 (ball 3 is in cup 3)
Good luck!
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers57
Suggested Problems
-
Maximum running product for a string of numbers
2253 Solvers
-
Create a function handle that reverses the input arguments of another function handle
157 Solvers
-
405 Solvers
-
Create a Multiplication table matrix...
690 Solvers
-
Implement a bubble sort technique and output the number of swaps required
386 Solvers
More from this Author80
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
I think that with this kind of problem, you can process in two steps.
A first easy problem with small N (to test perms for example). And a harder problem with big N, which
oblige to find another algorithm.
http://oeis.org/A000166