How do I find the count of sub-arrays whose sum of elements is divisible by $3$? The elements are to be chosen from $0,1,2$. These elements can appear any number of time in array. The number of appearance of the elements is also given.
For example: $$[0,1,2]$$ Number of 0's = 1 Number of 1's = 1 Number of 2's = 1
Answer is $4$: as valid sub-arrays are $$[], [0], [1,2], [0,1,2] $$
Note: Instead of generating all the possible sub-arrays, looking for a way to compute the subset count by using the appearance count of elements, e.g., occurrence of 0's, 1's, and 2's
Looked into following but couldn't use it for the problem: How do I count the subsets of a set whose number of elements is divisible by 3? 4?
(1) Finding an exact solution to this variant --- or even the original --- subset sum problem is non-trivial for large sets of boxes.
(2) It is known that the probability mentioned above is 1/3 only in the limit of an infinitely large set of boxes.
(3) The discrepancy between your analysis and the empirical probabilities lies in how your uniformly distributed epsilon_i variables correspond only approximately to anything in the real problem. For any N, the count of numbers <= N, grouped by mod 3, are not equal to each other.
– PDE Sep 01 '20 at 05:05