dp
of size target + 1
with all elements set to 0.dp[0]
to 1, as there is one combination to reach the sum of 0 (no elements).i
from 1 to target
(inclusive).
a. For each num
in nums
, if i - num
is not negative, increment dp[i]
by dp[i - num]
.dp[target]
as the result, which represents the number of combinations to reach the target sum.