Could you rewrite that program, but minimizing a sum of costs rather than maximizing a probability?