Memory-Efficient Dynamic Programming for Learning Optimal Bayesian Networks