Exact and Approximation Algorithms for Entropy Sampling and Stochastic Optimization