This is in regards to a problem for finding a number of combinations of an ordered set, where the elements have constraints.
As an example:
a+b+c+d+e=635, which may be…
[0-90] + [1-120] + [50-150] + [20-200] + [30-250] = 635
One solution uses multiple summations, as it was answered in the mathematics stack exchange.
https://math.stackexchange.com/questions/159197/combinatorics-using-constraints-and-ordered-set
Can someone please give a general idea of the procedure or pseudo-code to solving this type of problem?
Thank you very much!
A bunch of nested for-loops is the simplest way to do it.
Pseudocode:
Update
The above can be optimised a bit, but you end up with a specific, rather than general, solution.
You can observe that
(a+1) >= 1is always true, so we can get rid of themaxcall in the assignment tob. Likewise,(c+1) >= 20is always true, so the assignment todcan be simplified.You can also see that the maximum possible value of
a + b + c + dis 540, which gives a minimum possible value of 95 fore. This is greater than the stated lower bound fore, so we just have to check thate >= (d+1).We end up with: