Problem 1516. Put m balls into n boxes
Solution Stats
Problem Comments
-
5 Comments
I don't think you have a complete statement of the problem. Why, in the first example, are arrangements like 1 1 2 excluded? And you only accept the arrangements in a particular order. How do you define the order?
the data ascended by column,when the first column is the same, sort by the second column,...
Thanks - and I realize now that 1 1 2 is not excluded; I just wasn't looking carefully.
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
Problem Recent Solvers44
Suggested Problems
-
What is the distance from point P(x,y) to the line Ax + By + C = 0?
318 Solvers
-
Create Volcano (or Atoll) martix. It is an extension of Bullseye matrix problem.
115 Solvers
-
139 Solvers
-
Natural numbers in string form
761 Solvers
-
Number of Even Elements in Fibonacci Sequence
933 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!