CODHASH - Hashcodes and primes
There are n cards arranged in a row. The rth card from the left has rth prime number written on it on one side the other side is blank. Some cards have the blank side up and the others have the number side up.
Cards with their blank side up are known as 0-cards and cards showing the prime numbers are known as 1-cards.
A hash code is generated from the set of cards in the following way:
- Initial value of hashcode is 1.
- All the 0-cards should be turned upside down to convert them to a 1-card in order to get the final value of the hash code.
- At each step a 0-card can be turned upside down if there's at least one 1-card adjacent to it. Once the card is turned the value of the hash code is changed according to the following equation:
New value of hashcode = (Previous value of hashcode) * ((Number on the card)^(Number of 0-cards left on the table+1)) - Once all the cards on the table are 1-cards we get the final value of hash code.
Find the total number of distinct hash codes that can be generated like this for the given arrangement of cards.
Input
The first line contains 0 < T <= 1000 (T is the number of test cases)
The first line of every test case contains two integers n and m where n is the number of cards on the table and m is the number of 1-cards on the table, (1 ≤ n ≤ 1000, 1 ≤ m ≤ n). The second line contains m distinct integers, each between 1 to n inclusive, denoting the indices of the cards that are 1-cards.
Output
For every test case print in a separate line the number of distinct hash codes that can be generated for the given arrangement of cards modulo 1000000007 (10^9 + 7).
Example
Input: 2 3 1 1 4 2 1 4 Output: 1 2
Added by: | CSI |
Date: | 2013-09-28 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |