A Generalization of Grover's Algorithm