An interesting game

3

4 votes
Algorithms, Dynamic Programming, 2D dynamic programming, C++
Problem

Bob and James are about to play with an array A[] of N elements with Bob starting the game. In each turn :

  • A player selects a non-zero number of elements from A[] with the same value and removes them from A[].

The player whose turn makes array A[] becomes empty wins the game.

James is very intelligent and he modifies the game a bit. He selects some distinct elements (among those present in A) and removes all other elements which are not selected from A[]. The game is then played using this modified array.

For example, consider A=[1,1,3,12,2,34,2]. If James chooses values (1,2,34), then the array with which the game is played is [1,1,2,34,2].

Find the number of possible subsets of elements that James can select to modify A[] such that James is bound to win if both the players play optimally.

Consider an empty subset as a valid answer.

Since the number of possible subsets can be large enough, print the answer modulo 109+7.

Input format

  • The first line contains an integer T denoting the number of test cases.
  • The second line contains an integer N.
  • The next line contains N space-separated integers, denoting elements of A[].

Output format

For each test case, print the number of possible subsets satisfying the criteria modulo 109+7 in a new line.

Constraints

1T101N2×1051A[i]1018

 

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

Two possible solutions are :-

  • Empty Subset
  • {1,2}
Editor Image

?