If only I could think Linearly...
Time limit1sMemory limit128 MB
Given a matrix M and output vector y, find the three nonzero entries of the input vector x with Mx equal to y.
- Level
Medium6 of 10
- Topics
- Matrix, Brute force
- Solved
- No attempts yet
Problem
Any true algorithm junkie knows that a linear system with an input vector and an output vector can be described by a single matrix . Column of holds the outputs you get when input is one and every other input is zero. Because the system is linear, the output for an arbitrary combination of inputs is a linear combination of the columns of .
You are given the matrix and the output vector . Find the input that produces that output. is an matrix, is a column vector of size , and the you are looking for is a column vector of size with exactly three non-zero entries. Written out for and , the task is to find the that satisfies this equation.
You also have to handle the case where the number of inputs is larger than the number of outputs . The system is then underdetermined and several different produce the same , but only one has exactly three non-zero entries.
Input
The first line contains the number of rows of the matrix , and the second line contains the number of columns . Each of the next lines contains one row of as real numbers separated by whitespace. Each of the following lines contains one entry of the output vector .
, , and an satisfying the condition always exists and is unique. One input holds a single test case.
Output
Print the indices of the three non-zero entries in increasing order, one per line, in this format.
input i = v
is an integer between 1 and , and is the value of that input rounded to two decimal places. No answer value sits close enough to a rounding boundary for the rounding direction to be in doubt.
Hint
Multiplying by the correct reproduces every entry of to within a relative error of 0.01%. The non-zero entries can sit in only places, so you can solve the least squares problem for each candidate triple of columns and keep the triple whose residual is close to zero. The three indices have to match the correct answer exactly.