The restaurants are numbered $1$ through $N$ from west to east, and the distance between restaurant $i$ and $i+1$ is $A_i$. Say $1 \leq i \leq n$ and $1 \leq j \leq m$, and evaluating $C$ takes $O(1)$ Moreover, Dynamic Programming algorithm solves each sub-problem just once and then saves its answer in a table, thereby avoiding the work of re-computing the answer every time. Allows you to reduce O (N 2) to O (N lo g N). Dynamic programming approach extends divide and conquer approach with two techniques (memoization and tabulation) that both have a purpose of storing and re-using sub-problems solutions that may drastically improve performance. Dynamic programming is both a mathematical optimization method and a computer programming method. Like Divide and Conquer, divide the problem into two or more optimal parts recursively. The divide and conquer optimization applies when the dynamic programming recurrence is approximately of the form \[ \mathrm{dp}[k][i] = \min_{j
2020 divide and conquer dp optimization