I have an array of size n
of integer values and a given number S
.
1<=n<=30
I want to find the total number of sub-sequences such that for each sub-sequences elements sum is less than S
.
For example: let n=3
, S=5
and array's elements be as {1,2,3}
then its total sub-sequences be 7
as-
{1},{2},{3},{1,2},{1,3},{2,3},{1,2,3}
but, required sub sequences is:
{1},{2},{3},{1,2},{1,3},{2,3}
that is {1,2,3}
is not taken because its element sum is (1+2+3)=6
which is greater than S
that is 6>S
. Others is taken because, for others sub-sequences elements sum is less than S
.
So, total of possible sub-sequences be 6
.
So my answer is count, which is6
.
I have tried recursive method but its time complexity is 2^n
.
Please help us to do it in polynomial time.