I'm looking for an efficient solution to a specific case of integer factorization. By efficient I mean considerably faster than O(2^n)
, which I currently have (n represents the number of elements in the array after we are done).
Suppose we have the following array: [4, 5, 11]
and a "goal" of 84.
We want to find out if it's possible to satisfy 4*a + 5*b + 11*c = 84
,
given the following constraints:
- 0 <= a <= 3
- 0 <= b <= 2
- 0 <= c <= 1
If we don't find a solution, we add an integer to the array, let's say 15: [4, 5, 11, 15]
Now we want to know if anything satisfies 4*a + 5*b + 11*c + 15*d = 84
given that
- 0 <= a <= 4
- 0 <= b <= 3
- 0 <= c <= 2
- 0 <= d <= 1
...and we repeat the process until we find a solution, or up to n times. I was wondering if we could exploit the repetitive properties of the problem to find an efficient solution:
- The "goal" doesn't change
- The integers come in ascending order
- The max constraints for a,b,c... increase by 1 every time we add a new element
- Every repeat something is added to the formula, but nothing is changed (other than the constraints)
Any ideas?