0

I have a pretty simple question that I cannot answer...

Imagine that you have a number of different sets, denoted by $H$, and each set has a list of numbers. For example, let's say that there are 3 sets of numbers, so: $H_{1} = \{1,2,3\}$, $H_{2} = \{1,2\}$, and $H_{3} = \{1\}$.

Now imagine that there is a target number, $x > 0$. If we are only allowed to select one number from each set and add them together (but not all sets have to be used), how many combinations would lead to $x$?

For example, assuming $x = 4$, there are 5 combinations using the sets above that would lead to 4.

Is there a general formula to compute the number of different combinations that can be selected that lead to $x$?

Note that each set of numbers begins at 1.

Owen
  • 3
  • Do you want a computer algorithm? Also, does it matter from which set each number was taken? – Asinomás Jan 14 '15 at 16:04
  • Sure, if an algorithm is the only way to go about it. Doesn't matter which sets are used. Not all sets have to be used, and sets are interchangeable I guess. – Owen Jan 14 '15 at 16:06

1 Answers1

0

If the sets where completely arbitrary it would be a lot harder (there would probably be computational complexity results backing that claim up, but I don't know about that stuff).

However as the problem stands now what you want to count can be rephrased as follows. You want to count the number of integer non-negative solutions to $x_1+x_2+x_3\dots +x_n=x$ with $x_1\leq a_1,x_2\leq a_2\dots ,x_n\leq a_n$. This problem is hard (although not nearly as hard as if you had allowed for arbitrary sets).

Here is a link on math.se discussing how to solve the problem you asked.

Asinomás
  • 105,651
  • I see that there may be no closed-form solution to this general problem. A purely algorithmic route is the way to go it seems! – Owen Jan 14 '15 at 16:30