Zeroing a Binary Sequence
Time limit1sMemory limit256 MB
Count ordered flip sequences of exactly K moves that turn a given binary sequence into all zeroes.
- Level
Medium5 of 10
- Topics
- Combinatorics, Dynamic programming
- Solved
- No attempts yet
Problem
Adam likes solving challenges. He is given a binary sequence of length .
Adam makes exactly moves. On each move he picks one element of the sequence and flips it, so a 0 becomes 1 and a 1 becomes 0. After all moves the sequence must contain only zeroes.
Adam solves this easily, but he wants to know how many ways there are. Print the number of ways modulo .
Two ways count as different if there is an such that they pick different elements on the -th move.
Input
The first line contains an integer (), the number of test cases. The test cases follow.
The first line of each test case contains two integers () and (), separated by a space. is the length of the sequence and is the number of moves. Each of the next lines contains 0 or 1, one element of the sequence, given in the order of the sequence.
Output
For each test case, print one line in the form Case #X: Y, where is the test case number starting from 1 and is the number of ways modulo .