This animation shows how dynamic programming solves the problem:
"In how many ways can we achieve a target score of 8 using only moves of value 3 and 5?"
Step 0: Initial State
Score → State ↓
0
1
2
3
4
5
6
7
8
Initial
1
0
0
0
0
0
0
0
0
After Move 3
1
0
0
0
0
0
0
0
0
After Move 5
1
0
0
0
0
0
0
0
0
We start with dp[0] = 1 (there's 1 way to make a score of 0 - by doing nothing).
All other cells are initialized to 0 (no ways to achieve those scores yet).