Genetic algorithm is a classic algorithm for optimization. But there are some problems with it, such as prematurity, inefficiency. Another improved method is offered in the article. Some points in the article: first, make sure that all the chromosomes in the first generation are distributed. Second, in the crossover operation, decide if making a crossover between two chromosomes or not according to their generalized hamming distance. If the chromosomes matched can't make a crossover, and then mutate the two chromosomes until they can. After mutation check all the chromosomes but the top one of the new generation. Revise all the repeated chromosomes by mutation until they aren't. A test shows that the algorithm offered in the article can get the optimum result rapidly.