Cutting the Long Cake
InterviewTime limit2sMemory limit512 MB
Count the ways to make k-1 cuts in a cake of n cells so that every piece has the same number of toppings, modulo 1e9+7.
- Level
Medium5 of 10
- Topics
- Combinatorics, Math, Array
- Solved
- No attempts yet
Problem
Albert baked a long cake of length . The cake is divided in advance into cells so that it can be split into equal parts, and some cells have fruit toppings.
For example, the figure below shows a cake with , where is a cell without a topping and is a cell with a fruit topping. As an integer array, this is . is if the -th cell has a topping and if it does not.

Albert wants to cut this cake exactly times to make pieces. The cuts must satisfy the following conditions.
- Condition 1: Every cake piece must contain the same number of cells with toppings.
- Condition 2: No cell or piece may be discarded.
For example, when , there are ways to cut the cake above without discarding any cell or piece. Three of them satisfy condition 1. Each piece has two cells with toppings in these ways.



As another example, the figure below shows two ways to cut a cake with , , and that satisfy both conditions.

Given , , and the array that shows whether each cell has a topping, count the number of ways to cut the cake that satisfy the conditions. The answer can be very large, so print it modulo .
Input
The first line contains the number of test cases .
Each test case is given in two lines. The first line contains and separated by a space. The second line contains the array as a string of length with no spaces.
Output
Print the answer for each test case on its own line.