Use of maximum principle for numerical solution of optimal control problems with terminal constraints