Advertisement
sorenFive

Untitled

Mar 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. long getWays(long n, vector < long > c, int i){
  6. int ways = 0;
  7. if(n == 0){
  8. return 1;
  9. }
  10. if(n > 0){
  11. if (i + 1 < c.size() ){
  12. ways += getWays(n, c, i + 1);
  13. }
  14. ways += getWays(n - c[i], c, i);
  15. }
  16.  
  17. return ways;
  18. }
  19.  
  20. int main() {
  21. int n;
  22. int m;
  23. cin >> n >> m;
  24. vector<long> c(m);
  25. for(int c_i = 0; c_i < m; c_i++){
  26. cin >> c[c_i];
  27. }
  28. // Print the number of ways of making change for 'n' units using coins having the values given by 'c'
  29. long ways = getWays(n, c, 0);
  30. cout << ways << endl;
  31. return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement