How to print all possible combinations of getting a required coin change in quadratic time or less?

Revision en1, by badam_milk, 2020-04-18 10:04:09

Hello everyone,

I have successfully managed to write a recursive program to print all possible combinations of getting a coin change, let's say value:

void print_possible_change(vector<int> &change, int beginWith, int value, vector<vector<int>> &res, vector<int> &temp){
	if(value == 0){
		res.push_back(temp);
	}

	for(int i = beginWith; i < change.size() && change[i] <= value; ++i){
		temp.push_back(change[i]);
		print_possible_change(change, i, value - change[i], res, temp);
		temp.pop_back();
	}
}

This approach is clearly run in exponential time.

Is there an approach that runs in quadratic time or less?

Thank You.

Tags #dp, #recursion, #combinatorics, #combination

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English badam_milk 2020-04-18 10:05:33 4 Tiny change: ' approach is clearly run in expone' -> ' approach clearly runs in expone'
en2 English badam_milk 2020-04-18 10:04:51 64
en1 English badam_milk 2020-04-18 10:04:09 764 Initial revision (published)