2

Good evening,

I've been doing some research for school and already tried some ways for this to work. I've also searched this in my math books.

Here is the problem.

Let's say I have a number N of bottles, a number K of containers. Each container can have a different capacity (how many bottles can fit into a container). Considering that all the bottles have to be put into recipients, I have to calculate the total number of possibilities of putting the bottles into containers. A solution is given when all the bottles are in the containers.

A concretely example: N=7 (7 bottles) K=2 (2 containers)

K1=3 (in container 1 fit in 3 bottles) K2=5 (in container 2 fit in 5 bottles)

The number of solutions for this example is : 2 Solution 1 : 3 4 (first container has 3 bottles , the other one has 4) Solution 2 : 2 5 (first container has 2 bottles , the other one has 5)

I need something that works for any number of bottles and containers. A formula, a source code in Java/C++. Any answer is welcomed.

More examples : 1. N=100 K=4 K1=25 K2=60 K3=100 K4=200 2. N=20 K=6 K1=10 K2=100 K3=1000 K4=2500 K5= 20 K6 =10

  • It is unfortunate no progress has been shown on this problem... I might look at it myself later – Brevan Ellefsen Nov 30 '15 at 20:11
  • I feel this problem is related to http://math.stackexchange.com/questions/926433/how-many-lists-of-100-numbers-1-to-10-only-add-to-700 – Harry Mar 03 '16 at 10:02

1 Answers1

0

I offer a possible approach:

The number of solutions equal to the coefficient of $x^N$ of the polynomial

$(1+x+x^2...+x^{K_1})(1+x+x^2...+x^{K_2})...(1+x+x^2...+x^{K_K})$

Err...

So a Mathematica code(If you don't mind) for this might be

solutions[N_, ks_] := Coefficient[Times @@ ((Total["x"^Range[0, #, 1]]) & /@ ks), "x"^N]

or more efficiency:

solutions[N_, ks_] := Coefficient[ Times @@ ((Total["x"^Range[0, #, 1]]) & /@ (If[# > N, N, #] & /@ ks)), "x"^N]

for your examples

solutions[100,{25,60,100,200}] gives 92781

while

solutions[20, {10, 100, 1000, 2500, 20, 10}] gives 49126

Harry
  • 111