AquaMoon and Chess
time limit per test: 1 second
memory limit per test: 256 megabytes
Articles
Cirno gave AquaMoon a chessboard of size . Its cells are numbered with integers from to from left to right. In the beginning, some of the cells are occupied with at most one pawn, and other cells are unoccupied.
In each operation, AquaMoon can choose a cell ii with a pawn, and do either of the following (if possible):
- Move pawn from it to the -th cell, if and the -th cell is occupied and the -th cell is unoccupied.
- Move pawn from it to the -th cell, if and the -th cell is occupied and the -th cell is unoccupied.
You are given an initial state of the chessboard. AquaMoon wants to count the number of states reachable from the initial state with some sequence of operations. But she is not good at programming. Can you help her? As the answer can be large find it modulo .
Input
The input consists of multiple test cases. The first line contains a single integer — the number of test cases.
The first line contains a single integer — the size of the chessboard.
The second line contains a string of characters, consists of characters “0” and “1”. If the -th character is “1”, the ii-th cell is initially occupied; otherwise, the -th cell is initially unoccupied.
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, print the number of states that reachable from the initial state with some sequence of operations modulo .
Example
Input
1 | 6 |
Output
1 | 3 |
Note
In the first test case the strings “1100”, “0110” and “0011” are reachable from the initial state with some sequence of operations.
思路
字符0每个都是一个独立的个体,每两个连续的字符1是一个独立的个体,使用组合数即可计算总的状态数。(单独的字符1不影响组合数的计算)
代码
1 |
|