Problem 1516. Put m balls into n boxes
Solution Stats
Problem Comments
-
6 Comments
The best way to generate such a sequence is using depth-first search or recursion. By prohibiting the usage of IFs, all solutions are inefficient (because we can't cut the tree, and are forced to follow all branches).
For the 3 balls 2 boxes cases, shouldn't the following be part of the answer as well?
1 2 1
2 1 1
2 1 2
2 2 1
Why is 'if' banned, @Binbin Qi? Due to this (stupid, in my opinion) ban, I can not use diff as well. I have put up a temporary change in place, but I suggest you to please fix the problem asap.
And if you are putting up restrictions on the test suite, please mention it in the problem statement.
Also, your own solution and the reference solution do not work.
Solution Comments
Show commentsProblem Recent Solvers66
Suggested Problems
-
Remove all the words that end with "ain"
2422 Solvers
-
Find common elements in matrix rows
2667 Solvers
-
2290 Solvers
-
Rotate input square matrix 90 degrees CCW without rot90
637 Solvers
-
5553 Solvers
More from this Author17
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!