Efficient, high-level dynamic programming