Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- class Solution {
- static long getWays(long n, long[] coins){
- long[] temp = new long[n + 1];
- temp[0] = 1;
- for(int i = 0; i < coins.Length; i++) {
- for(int j = 1; j <= n; j++) {
- if(j >= coins[i])
- temp[j] += temp[j - coins[i]];
- }
- }
- return temp[n];
- }
- static void Main(String[] args) {
- string[] tokens_n = Console.ReadLine().Split(' ');
- int n = Convert.ToInt32(tokens_n[0]);
- int m = Convert.ToInt32(tokens_n[1]);
- string[] c_temp = Console.ReadLine().Split(' ');
- long[] c = Array.ConvertAll(c_temp,Int64.Parse);
- // Print the number of ways of making change for 'n' units using coins having the values given by 'c'
- long ways = getWays(n, c);
- Console.WriteLine(ways);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement