Suppose a product comes in packs of 3, and 5, and a customer demands 8 quantities of that product.
1 = (1)3 + (1)5
But, if a customer demands 4 products, it isn't possible, there is no solution that can give you the sum 7 for the packs of 3, and 5.
My approach:
n = (x)a + (y)b
a and b are quantities in two packs, and x & y are to be determined. I'll apply different combination starting from (0,1), (1,0), (1,1) till (b,b) assuming b > a. I don't know what this problem is called in Mathematics. Is there a solution already developed for it, or what would be the best approach for it?
Pardon my English, and the way I wrote this question. I'm just a beginner.
Edit: The number of total packs can vary. In above statement, there were 2 packs available, and in general, it can be n pack where is any positive integer greater than 1.
There is a very simple algorithm which determines if the solution exists or not, a problem very close to this is the Frobenius coin problem.
So suppose you have packages of sizes $a$ and $b$, we can assume $a$ and $b$ are coprime, otherwise make the suitable modifications. For a given $n$ you wish to find non-negative integers $x$ and $y$ so that $xa+yb=n$.
Here is the algorithm you need:
First take $x=na^{-1}\bmod b$ and reduce it (so that $x=\{0,1,2\dots b-1\}$).
Notice that $\frac{n-xa}{b}$ will be an integer, if it is negative there is no solution, otherwise taking $y=\frac{n-xa}{b}$ gives the solution.
Here is the napsack c++ code, it runs in time $N\times K$ ($N$ is desired number and $K$ is the number of sizes).