Joseph's coin trouble

3.8

11 votes
Problem

Joseph studies at SKIT.He is a fresher he has been given a task and he wants help from you for performing the task.The task is an interesting one.

The tasks is:-

He is provided with a value N, he has to make change for N cents, and he have infinite supply of each of S = { S1, S2, S3, S4} valued coins, how many ways can he make the change? The order of coins doesn't matter. Maximum types of coins available are only 4.

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}.

Now his job is to find out no of ways he can make the change as for above example the result will be 4.

INPUT

First line denotes N. Second line denotes S which is no of types of coins in string format.

OUTPUT

An integer which shows the no of ways he can make the change

CONSTRAINTS

MAXIMUM VALUE OF N,S1,S2,S3,S4 CAN BE 9000000.

Sample Input
10
2 4 9
Sample Output
3
Time Limit: 5
Memory Limit: 256
Source Limit:
Editor Image

?