Optimized preparation of quantum states by conditional measurements.