Mluran Storage
Time limit2sMemory limit256 MB
Count the ways to 2-color isotopes 1..n so that no two masses summing to a given power-of-two critical number share a color, mod 1e9+7.
- Level
Hard8 of 10
- Topics
- Graph, Math, Combinatorics, Implementation
- Solved
- No attempts yet
Problem
Mluran, a chemical element discovered in 2345, is highly radioactive. Mishandling mluran can lead to unpredictable consequences, so special care must be taken when using, storing, and transporting it.
There are many different isotopes of mluran, each characterized by a natural number, its atomic mass. When any pair of isotopes whose masses sum to one of "critical numbers" is stored together for a long time, the pair reacts and explodes. All critical numbers are nonnegative powers of two.
At the nuclear laboratory of Flatland, mluran samples are stored in two special warehouses. Scientists have obtained different mluran isotopes whose masses are the numbers from 1 to . Now these isotopes must be distributed among the warehouses for storage. A storage method is called safe if each isotope is stored in exactly one warehouse and any two different isotopes whose masses sum to one of the "critical numbers" are stored in different warehouses.
Help the scientists find out how many different safe ways to store mluran exist.
Input
The input contains several test sets. Each set is described by two lines.
The first line of the description contains two integers and (, ), the number of isotopes to store and the number of "critical numbers". The next line contains different natural numbers, each a power of two and not exceeding , the critical numbers. The critical numbers are separated by spaces.
The number of data sets in each test does not exceed 10000. The last line of the test contains two zeros.
Output
For each test set, output on a separate line the number of safe ways to store all isotopes in two warehouses, modulo .