Problem I
Cheating a Boolean Tree
For this problem we will consider a type of binary tree that we will call a boolean tree. In this tree, every row is completely filled, except possibly the last (deepest) row, and the nodes in the last row are as far to the left as possible. Additionally, every node in the tree will either have 0 or 2 children.
What makes a boolean tree special is that each node has a boolean value associated with it, 1 or 0. In addition, each interior node has either an "AND" or an "OR" gate associated with it. The value of an "AND" gate node is given by the logical AND of its two children’s values. The value of an "OR" gate likewise is given by the logical OR of its two children’s values. The value of all of the leaf nodes will be given as input so that the value of all nodes can be calculated up the tree.
The root of the tree is of particular interest to us. We
would really like for the root to have the value
Given a description of a boolean tree and what gates can be changed, find the minimum number of gates that need to be changed to make the value of the root node V. If this is impossible, output "IMPOSSIBLE" (quotes for clarity).
Input
The first line of the input file contains the number of
cases,
Each case begins with
The first
The next

Output
For each test case, you should output:
Case #X: Y
where
Sample Input 1 | Sample Output 1 |
---|---|
2 9 1 1 0 1 1 1 1 0 0 1 0 1 0 1 5 0 1 1 0 0 1 1 0 |
Case #1: 1 Case #2: IMPOSSIBLE |