Santa is preparing special gift bundles for children this holiday season. He has a list of different gift types, each with an associated "joy value". Santa wants to know in how many unique ways he can create a bundle of gifts such that the total joy exactly equals a given target value. Each gift type can be chosen an unlimited number of times. Order does not matter; for example, a bundle with gifts [2, 3, 3]
is considered the same as [3, 2, 3]
.
Write a function countGiftBundles(gifts, target)
that calculates the number of unique combinations of gift selections that sum up exactly to the target joy value.
gifts
representing the joy values of each gift type.target
representing the desired total joy value.Return an integer indicating the number of unique combinations that sum up to the target joy.
For example, if gifts = [2, 3, 5]
and target = 8
, some valid bundles (order ignored) might be:
[3, 5]
[2, 2, 2, 2]
[2, 3, 3]
Your function should return the total count of valid combinations.
Consider using dynamic programming to build up the solution by solving smaller subproblems for each possible joy value up to the target.
Happy coding and enjoy the holiday season!