Counting Sequences

View as PDF

Submit solution

Points: 10 (partial)
Time limit: 1.0s
Memory limit: 64M

Author:
Problem types

Let S denote a finite sequence of numbers. A subsequence of S consists of some terms of S in their original order. S is considered to be a subsequence of itself. An empty sequence of S is also a subsequence of S. For any sequence S, let N(S) denote the number of distinct subsequences of S. For example, if S = \{3, 4, 3, 4\}, then N(S) = 12, because S has the following 12 distinct subsequences:

\varnothing 3 4 3, 3
3, 4 4, 3 4, 4 3, 3, 4
3, 4, 3 3, 4, 4 4, 3, 4 3, 4, 3, 4

Input Specification

The first line will contain an integer T (1 \le T \le 25), representing the number of test cases.

The next T test cases will consist of two lines.

The first line will contain N (0 \le N \le 50), representing the number of numbers in S. For 30% of the points, 0 \le N \le 5.

The next line will contain N space-separated digits (0-9), representing each number in S.

Output Specification

For every test case, output the value of N(S) on a new line. N(S) is not guaranteed to fit in a 32-bit signed integer.

Sample Input 1

2
0

4
1 2 2 1

Sample Output 1

1
11

Explanation 1

The first and only subsequence of S of the first test case is simply \varnothing, due to S being an empty set.

The subsequences of S for the second test case are:

\varnothing 1 2 1, 1
1, 2 2, 1 2, 2 1, 2, 1
1, 2, 2 2, 2, 1 1, 2, 2, 1

Sample Input 2

2
8
6 6 6 6 6 6 6 6
3
1 2 3

Sample Output 2

9
8

Explanation 2

For the first test case, the subsequences of S are:

\varnothing
6
6, 6
6, 6, 6
...
6, 6, 6, 6, 6, 6, 6, 6

For the second test case, the subsequences of S are:

\varnothing 1 2 3
1, 2 2, 3 1, 3 1, 2, 3

Comments

There are no comments at the moment.