You are provided with a collection of items, each having a unique weight. A buyer wishes to purchase a set of these items, subject to two strict conditions set by the market rules:
Given the available item weights, write a program to calculate the total number of distinct combinations (subsets) of exactly $N$ items that sum up to exactly $W$.
20
3 10
1 2 4 5 10 11 13 15 17 19
4
Explanation 1: The target weight is $W = 20$, and the required number of items is $N = 3$. The 4 valid combinations of 3 items that sum to 20 are:
45
7 19
1 2 4 5 6 8 9 10 12 13 15 16 17 18 19 20 21 23 24
12
Explanation 2: The target weight is $W = 45$, and the required number of items is $N = 7$. There are exactly 12 distinct subsets of 7 items from the given array that sum to 45 (e.g., {1, 2, 4, 5, 6, 8, 19}, {1, 2, 4, 5, 6, 9, 18}, etc.).
Intuit • Pending
Intuit • Pending
Intuit • Pending
Intuit • Pending