To assure the opacity, an optimal problem is to retain the occurring events sequences as many as possible. Contrary to such problem, the other optimal problem is to preserve the minimal occurring events sequences. In the paper, based on the choosing cost, an optimal opacity-enforcing model is presented to minimize the sum of discount choosing cost, which is not only to preserve the opacity, but also to retain the secret to the maximum. To solve the model, two scenarios on opacity are considered. For the two scenarios, some algorithms are presented to achieve the optimal solution for the model by using the method of dynamic programming. And then, the solutions produced by the algorithms are proved correctly by theoretical proof. Finally, some illustrations for the algorithms are given.