A straightforward implementation of DBM
