Quantum speedups for dynamic programming on $ n $-dimensional lattice graphs