Loading...
Loading...
Loading...
A shop has n gift cards with given values. Count the different groups of cards whose values add up to exactly the target. Cards with equal values are different cards.
Example
Input
3 8 3 5 8
Output
2
The groups {3, 5} and {8}.
Try the problem first. Open one hint at a time.
With n up to 15 there are at most 32768 subsets, so try them all.
Loop mask over range(1 << n) and add the values whose bit is set.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor