Problem Statement
How many different ways can you make change for an amount, given a list of coins? In this problem, your code will need to efficiently compute the answer.
Problem Statement
Write a program that, given two arguments to STDIN
- a list of coins
c1, c2, c3, ..
- and an amount
n
Prints out how many different ways you can make change from the coins to STDOUT.
The problem can be formally stated:
Given a value N
, if we want to make change for N
cents, and we have infinite supply of each of C = { C1, C2, .. , Cm}
valued coins, how many ways can we make the change? The order of coins doesn’t matter.
Example 1:
For N = 4
and C = {1,2,3}
there are four solutions: {1,1,1,1},{1,1,2},{2,2},{1,3}
So given the input
1, 2, 3 4
your program should output:
4
for(int i=0;i<A.size();i++)
for(int j=1;j<=m;j++)
for(int k=A[i];k<=N;k++) dp[j][k]+=dp[j-1][k-A[i]];