Let S={1,2,3,5,7,10,11}. The number of non-empty subsets of S that have the sum of all elements a multiple of 3, is _____ .
Question
Let S={1,2,3,5,7,10,11}. The number of non-empty subsets of S that have the sum of all elements a multiple of 3, is _____ .
Solution
This problem can be solved by using the concept of Dynamic Programming. Here are the steps:
-
First, we need to find the sum of all elements in the set S. The sum is 1+2+3+5+7+10+11 = 39.
-
We need to create a 2D array dp[i][j], where i ranges from 0 to 7 (the number of elements in the set) and j ranges from 0 to 39 (the sum of all elements). The value of dp[i][j] will be the number of subsets of the first i elements that have a sum equal to j.
-
Initialize the dp array. For i=0 (no elements), the sum is always 0, so dp[0][j] = 0 for all j. Also, there is always one subset (the empty set) that has a sum of 0, so dp[i][0] = 1 for all i.
-
Now, fill the rest of the dp array. For each element in the set (let's call it num), and for each possible sum j from num to 39, update dp[i][j] = dp[i-1][j] + dp[i-1][j-num]. This means that the number of subsets of the first i elements that have a sum equal to j is the number of subsets of the first i-1 elements that have a sum equal to j (not including num), plus the number of subsets of the first i-1 elements that have a sum equal to j-num (including num).
-
After filling the dp array, we need to find the number of subsets that have a sum multiple of 3. This is the sum of dp[7][j] for all j that are multiples of 3.
-
So, the answer is dp[7][0] + dp[7][3] + dp[7][6] + ... + dp[7][39].
This is a complex problem that requires a good understanding of dynamic programming and subset sums.
Similar Questions
Ten whole numbers are arranged in a row so that the sum and the difference of any two adjacent numbers are not multiples of 3. How many of these ten whole numbers are multiples of 3?
S = {1, 2, 3, 4, 5 … N}, where N is greater than 5. X is a set consisting of all the possible four-element subsets of S. The sum of all the numbers in all the elements of X is ______.
If A={1, 2, 3, 4}, then the number of the subsets of A that contain the element 2 but not 3, is?
How many subsets of the set {1, 2, 3, 4} that contain 3?Select one:a.9b.3c.8d.16
Given a set of non-negative integers, and a value S, determine if there is a subset of the given set with sum equal to S.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.