Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- long getWays(long n, vector < long > c, int i){
- int ways = 0;
- if(n == 0){
- return 1;
- }
- if(n > 0){
- if (i + 1 < c.size() ){
- ways += getWays(n, c, i + 1);
- }
- ways += getWays(n - c[i], c, i);
- }
- return ways;
- }
- int main() {
- int n;
- int m;
- cin >> n >> m;
- vector<long> c(m);
- for(int c_i = 0; c_i < m; c_i++){
- cin >> c[c_i];
- }
- // Print the number of ways of making change for 'n' units using coins having the values given by 'c'
- long ways = getWays(n, c, 0);
- cout << ways << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement