Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. class Solution {
  6.  
  7. static long getWays(long n, long[] coins){
  8. long[] temp = new long[n + 1];
  9. temp[0] = 1;
  10. for(int i = 0; i < coins.Length; i++) {
  11. for(int j = 1; j <= n; j++) {
  12. if(j >= coins[i])
  13. temp[j] += temp[j - coins[i]];
  14. }
  15. }
  16. return temp[n];
  17. }
  18.  
  19. static void Main(String[] args) {
  20. string[] tokens_n = Console.ReadLine().Split(' ');
  21. int n = Convert.ToInt32(tokens_n[0]);
  22. int m = Convert.ToInt32(tokens_n[1]);
  23. string[] c_temp = Console.ReadLine().Split(' ');
  24. long[] c = Array.ConvertAll(c_temp,Int64.Parse);
  25. // Print the number of ways of making change for 'n' units using coins having the values given by 'c'
  26. long ways = getWays(n, c);
  27. Console.WriteLine(ways);
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement