1 1 1
1 1 2
1 2 2
2 2 2
The columns stand for a ball, the number stands for a box, and the row stands for a case.
Now we count the number of balls in each boxes.
so we get
3 0
2 1
1 2
0 3
the 1-th row stand for the 1-th case,3 balls are put into the first boxes,the others is empty the 2-th row stand for the 2-th case,2 balls are put into the first boxes,1 balls is put into the second boxes
You should write a function, input m and n, m stand for the number of balls ,n stand for the number of boxes,output all the cases.
Example
If m = 3,n = 4, you should output
3 0 0 0
2 1 0 0
2 0 1 0
2 0 0 1
1 2 0 0
1 1 1 0
1 1 0 1
1 0 2 0
1 0 1 1
1 0 0 2
0 3 0 0
0 2 1 0
0 2 0 1
0 1 2 0
0 1 1 1
0 1 0 2
0 0 3 0
0 0 2 1
0 0 1 2
0 0 0 3
Solution Stats
Problem Comments
2 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers65
Suggested Problems
-
Project Euler: Problem 3, Largest prime factor
1814 Solvers
-
312 Solvers
-
Back to basics 22 - Rotate a matrix
938 Solvers
-
Number of 1s in a binary string
11414 Solvers
-
Remove entire row and column in the matrix containing the input values
567 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!
I'm not sure what is the point of eliminating 'ifs'? At any rate they can be easily replaced by e.g. 'while' loops, so in my opinion you should either eliminate both of them or none.
Again, 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).