fork(4) download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int helper(int target, vector<int>& coins, vector<int>& cache, int min) {
  6. if(target < 0) return 0;
  7. if(target == 0) return 1;
  8. //if(cache[target] != 0) return cache[target];
  9. //cout << min << endl;
  10. for(auto& c : coins) {
  11. if(target >= c && min <= c) {
  12. cout << min << " " << c << " " << target << endl;
  13. cache[target] += helper(target-c, coins, cache, c) ;
  14. //cout << cache[target] << endl;
  15. }
  16.  
  17. }
  18.  
  19. return cache[target];
  20.  
  21. }
  22.  
  23.  
  24. int main() {
  25. // your code goes here
  26. vector<int> coins{2, 3};
  27. //cout << coins.size();
  28. int target = 7;
  29. vector<int> cache(target+1, 0);
  30. cache[0] = 1;
  31. cache [7] = helper(target, coins, cache, 1);
  32.  
  33. for (auto& x : cache) cout << x << endl;
  34. return 0;
  35. }
Success #stdin #stdout 0s 4428KB
stdin
Standard input is empty
stdout
1 2 7
2 2 5
2 2 3
2 3 3
2 3 5
1 3 7
3 3 4
1
0
0
1
0
1
0
1