Straightforward implementation of DBM
