-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy patharavind.java
More file actions
31 lines (28 loc) · 919 Bytes
/
aravind.java
File metadata and controls
31 lines (28 loc) · 919 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner scan = new Scanner(System.in);
int N = scan.nextInt();
int M = scan.nextInt();
long[] coins = new long[M];
for(int i = 0; i < M; i++) {
coins[i] = scan.nextInt();
}
System.out.println(max(coins, N));
}
public static int max(int[] coins, int N) {
int[] numCoins = new int[N+1];
numCoins[0] = 1;
for(int i = 0; i < coins.length; i++) {
for(int j = coins[i]; j < numCoins.length; j++) {
numCoins[j] += numCoins[j - coins[i]];
}
}
return numCoins[N];
}
}