memo
with dimensions [locations.length][fuel + 1]
initialized to -1
.dfs
that takes the current city and remaining fuel as parameters.
memo
, return the stored value.dfs
with the new city and updated fuel.memo
before returning it.dfs
function with the start city and initial fuel.10^9 + 7
.