Overview
This is a combinatorics variant of the unbounded knapsack problem. Instead of minimizing, we are summing all distinct ways to form amounts.
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Find the total number of combinations that make up a given amount using given coins.
This is a combinatorics variant of the unbounded knapsack problem. Instead of minimizing, we are summing all distinct ways to form amounts.
Let `dp[i]` be the number of ways to make amount `i`. Initially, `dp[0] = 1` (doing nothing is 1 way).
For each coin, any amount `i` can be reached by adding the coin to amount `i - coin`. So we add `dp[i - coin]` to `dp[i]`.
Iterating coins on the outer loop guarantees we only consider combinations (ignoring order) rather than permutations.