Odd Subsequence
Time limit3sMemory limit512 MB
Count the distinct multisets chosen as subsequences whose element sum has an odd number of odd digits (1, 3, 5, 7, 9 in the decimal representation).
- Level
Medium7 of 10
- Topics
- Combinatorics, Array, Math, Implementation
- Solved
- No attempts yet
Problem
For an array of nonnegative integers, a "subsequence" is any array obtained by deleting zero or more elements.
A subsequence of is called an "odd subsequence" of if it satisfies the following condition:
- The number of odd digits in the sum of the elements of is odd.
Given an array of nonnegative integers, output the number of distinct odd subsequences of . Two subsequences are considered the same if sorting their elements yields the same result.
For , the answer is 8.
- Odd subsequences of length 0: none
- Odd subsequences of length 1:
- The sum is 3, and the only odd digit is 3
- Odd subsequences of length 2: , ,
- The sums are 9, 12, 14, each with exactly one odd digit: 9, 1, 1
- Odd subsequences of length 3: ,
- Odd subsequences of length 4: ,
- Odd subsequences of length 5: none
Input
The first line contains the number of test cases ().
For each test case, the first line contains the length of . The second line contains nonnegative integers separated by spaces. Each element of is between 0 and 2,000 inclusive.
Output
For each test case, print the number of odd subsequences on one line.
Hint
- Test case 1: there are three odd subsequences: , , .
- Test case 2: there are eight odd subsequences: , , , , , , , .
- Test case 3: as described in the problem, there are eight odd subsequences.