Sylvester construction
Time limit1sMemory limit128 MB
Given a Hadamard matrix built by the Sylvester doubling rule, print a small rectangular sub-matrix specified by its top-left corner.
- Level
Medium7 of 10
- Topics
- Divide and conquer, Recursion, Bit manipulation, Math
- Solved
- No attempts yet
Problem
A Hadamard matrix of order is an matrix whose entries are only and , written , satisfying , where is the identity matrix. A notable property of Hadamard matrices is that they attain the largest possible determinant among all matrices whose entries lie in . Hadamard matrices are used in error-correcting codes and in weighing designs.
The Sylvester construction builds a Hadamard matrix of size from :
For example,
and so on.
In this problem you must print a portion of a Hadamard matrix constructed in this way.
Input
The first number in the input is the number of test cases that follow. Each test case consists of five integers , , , , and . is a power of two with . The pair is the upper-left corner of the sub-matrix to print, where is the column index and is the row index; and are its width and height. Coordinates are zero-based, so . The sub-matrix always fits entirely inside the full matrix, and . There are at most test cases.
Output
For each test case, print the requested sub-matrix, with the entries in each row separated by single spaces. Print one blank line between the outputs of consecutive test cases.