How can i find the unique ways of putting N balls in K boxes,considering that one box only fits N/2 balls.Boxes can have 0 balls.
Test case
N=4 K=3

Possible combinations

2 2 0
2 0 2
0 2 2
2 1 1
1 1 2
1 2 1
  • 1
    $\begingroup$ Hint: can you do the problem without the cap? If so, then to conclude it helps to note that no unconstrained solution can violate the rule in more than one box...so now just study the solutions which do violate in exactly one box. $\endgroup$
    – lulu
    Jun 21, 2017 at 19:04
  • $\begingroup$ Note: your header doesn't match the body of the question (in one you say $\frac k2$ in the other you say $\frac N2$). Which did you intend? (my prior comment assumed you meant $\frac N2$). Also, you need to specify if the balls and or boxes are distinguishable. I would guess that you mean that the balls are indistinguishable but the boxes can be distinguished (but that is just a guess). $\endgroup$
    – lulu
    Jun 21, 2017 at 19:07
  • $\begingroup$ Yes i meant n/2 balls sorry @lulu $\endgroup$
    – Murad
    Jun 21, 2017 at 19:22
  • $\begingroup$ That's fine, but you still need to clarify whether the boxes are distinguishable or not. To be clear, if $N=4$ and $k=5$ are the two solutions $(2,2,0,0,0)$ and $(0,0,0,2,2)$ the same or are they different? (I am assuming you want the balls to be indistinguishable but if I am wrong about that you should say). $\endgroup$
    – lulu
    Jun 21, 2017 at 19:23
  • $\begingroup$ @lulu nope they are different. $\endgroup$
    – Murad
    Jun 21, 2017 at 19:24


You must log in to answer this question.

Browse other questions tagged .