Concepts

Dynamic programming state recurrence

Try the free JavaScript compiler

Reuse computed subproblem states. Specify base cases, dependencies, evaluation order, state bounds and the cost of computing each state.

Formal Syntax & Structure

javascript syntaxjavascript
dp[i] = combine(previous states)

Working Example

Example Snippetjavascript
const dp=[1,1];for(let i=2;i<=5;i++)dp[i]=dp[i-1]+dp[i-2];console.log(JSON.stringify(dp));
JavaScript Reference