Good Subsequence

4.5

2 votes
, Math, Observation, Basic Math, C++
Problem

You are given an array A of length N. A subsequence is called good if all the elements of that subsequence are distinct. Find the number of non-empty good subsequences modulo 109+7.

Two subsequences are different if they differ in the indices chosen.

Input Format:

  • The first line contains an integer T, which denotes the number of test cases.
  • The first line of each test case contains an integer N.
  • The second line of each test case contains N space-separated integers, elements of array A.

Output Format:

For each test case, print the number of non-empty good subsequences modulo 109+7.

Constraints:

1T101N1051A[i]105

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

First test case:
Good subsequences are [2],[3],[1],[2,3],[2,1],[3,1],[2,3,1]. Hence, the answer is 7.

Second test case:
Good subsequences are [1],[1],[1],[1]. Hence, the answer is 4.

Editor Image

?