Search for all possible sums of the set

I'm currently looking for ideas on how to find all the possible sums of a set of numbers with these rules. I have these numbers for work, and I want to find all possible amounts so that you can use only one number a maximum of 4 times and every time you select 7 of these numbers.

{0, 1, 5, 22, 98, 453, 2031, 8698, 22854, 83661, 262349, 636345 and 1479181}

Valid examples are

0 + 0 + 0 + 0 + 83 661 + 83 661 + 2031

An unacceptable example would be

0 + 0 + 0 + 0 + 0 + 83 661 + 2031

The only way I can think of is through a series of nested loops, but I also have problems with this. Will there be other options for this. I use Java, but I really don't think it matters.

+4
source share
1 answer

You can achieve this by creating a new list of elements containing each element of this set duplicated 4 times. then use the DFS strategy method to build a possible possible combination of amounts. have an idea on how to implement DFS validation this answer

+3
source

All Articles