Matrix nightmare
Time limit1sMemory limit1024 MB
Given a multivariate integer polynomial, construct a small matrix of integers and variables whose weighted traversal sum equals that polynomial, or report that none exists.
- Level
Hard10 of 10
- Topics
- Matrix, Combinatorics, Math, Implementation
- Solved
- No attempts yet
Problem
As Obi-Wan would put it: "This isn't the problem statement you are looking for. Move along."
The double factorial numbers are the numbers defined by the following recursive formula: , and : . For example, .
Sequences of length with all elements in the set are called limited sequences of order . For example, is a limited sequence of order . The set of all limited sequences of order is denoted .
The spread factor of a sequence is .
There is a direct isomorphism between pairs of sequences and sequences of pairs. Let with and . The corresponding sequence of pairs is denoted .
Pairs of integers are ordered lexicographically: if either , or (). A sequence of integer pairs is ordered lexicographically if for all . Let [if is ordered lexicographically then else ].
Let be an matrix with rows and columns indexed from to . Its elements are . A matrix is called a -var matrix if each element is either an integer or a variable. The -step traversal weight of is
Given is a multivariate polynomial with integer coefficients. Produce any reasonably small -var matrix such that .
Input
The first line of the input contains an integer , the number of test cases. Each test case is preceded by a blank line.
Each test case is a single line describing the polynomial. The variables are the letters a through z, and the syntax will be clear from the input file. Each polynomial has fewer than operations (additions, subtractions and multiplications).
Output
For each test case, output one matrix in the following format: its size , then all its elements in row major order. The elements may be separated by any positive amount of whitespace. The size of the matrix must not exceed . All integers must be between and , inclusive.
If no such matrix exists for a given polynomial, output a single zero instead.