This page is still under construction.

Parts of this page are still being built. What you see may change.

Zeroing a Binary Sequence

Time limit1sMemory limit256 MB

Summary
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 NN.

Adam makes exactly KK 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 KK 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 109+710^9 + 7.

Two ways count as different if there is an ii such that they pick different elements on the ii-th move.

Input

The first line contains an integer TT (1≤T≤501 \le T \le 50), the number of test cases. The TT test cases follow.

The first line of each test case contains two integers NN (1≤N≤10001 \le N \le 1000) and KK (1≤K≤10001 \le K \le 1000), separated by a space. NN is the length of the sequence and KK is the number of moves. Each of the next NN 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 XX is the test case number starting from 1 and YY is the number of ways modulo 109+710^9 + 7.

Examples5

  1. Example 1

    Input
    5
    1 10
    0
    1 11
    1
    1 10
    1
    2 30
    0
    0
    3 10
    0
    0
    0
    
    Expected output
    Case #1: 1
    Case #2: 1
    Case #3: 0
    Case #4: 536870912
    Case #5: 14763
    
  2. Example 2

    Input
    4
    1 1
    1
    1 1
    0
    2 2
    1
    1
    2 2
    0
    0
    
    Expected output
    Case #1: 1
    Case #2: 0
    Case #3: 2
    Case #4: 2
    
  3. Example 3

    Input
    3
    2 3
    1
    0
    3 5
    1
    1
    1
    4 4
    1
    0
    1
    0
    
    Expected output
    Case #1: 4
    Case #2: 60
    Case #3: 32
    
  4. Example 4

    Input
    3
    5 2
    1
    1
    1
    0
    0
    4 7
    0
    0
    0
    0
    6 1
    1
    1
    0
    0
    0
    0
    
    Expected output
    Case #1: 0
    Case #2: 0
    Case #3: 0
    
  5. Example 5

    Input
    4
    1 1000
    0
    1 999
    1
    1 999
    0
    1 1000
    1
    
    Expected output
    Case #1: 1
    Case #2: 1
    Case #3: 0
    Case #4: 0