A parametrization of the solutions of the finite-horizon LQ problem with general cost and boundary conditions