COIN CHANGE PROBLEM ( DE Shaw archives)

5

1 votes
Dynamic Programming
Problem

Given a value N, if we want to make change for N cents, and we have an infinite supply of each of S = { S1, S2, .. , Sm} valued coins, how many ways can we make the change? The order of coins doesn’t matter.

For example, for N = 4 and S = {1,2,3}, there are four solutions: {1,1,1,1},{1,1,2},{2,2},{1,3}. So output should be 4. For N = 10 and S = {2, 5, 3, 6}, there are five solutions: {2,2,2,2,2}, {2,2,3,3}, {2,2,6}, {2,3,5} and {5,5}. So the output should be 5.

Sample Input
4 3
1 2 3
Sample Output
4
Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

Example 1:

Input:

n = 4 , m = 3

S[] = {1,2,3}

Output: 4

Explanation: Four Possible ways are:

{1,1,1,1},{1,1,2},{2,2},{1,3}.

 

Example 2:

Input:

n = 10 , m = 4

S[] ={2,5,3,6}

Output: 5

Explanation: Five Possible ways are:

{2,2,2,2,2}, {2,2,3,3}, {2,2,6}, {2,3,5}  and {5,5}.

Contributers:
Editor Image

?