A polynomial-time recursive algorithm for some unconstrained quadratic optimization problems