Given an integer n
and s
sets of different sizes, but with positive ascending numbers from 0
to s_i
as elements. Let a good sum be defined here as a_1 + a_2 + ... + a_s = n
. Count how many sums are existent, when you take for every a_i
an element from it's corresponding set s_i
.
I tried to generate any possible way and omit those which are omittable, i.e. when you have for example s=3
, n=1
and you are given the sets s_0={0,1}
, s_1={0,1,2,3}
, s_2={0,1,2}
, then you can omit the check for the sum 0 + 0 + a_3
since a_3
won't be able to be large enough.
I've applied the dynamic programming solution for normal subset sum for each of those possible sequences, however, I get much larger results than I should and its very slow, too.
Are there any good algorithms which I can apply here?