Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
912 B
0
Indexable
Never
#include <bits/stdc++.h>

using namespace std;

vector<vector<int> > ans;



void helperfn(vector<int>& input,int i,int currSum,int target,vector<int>& temp){
    // cout<<"currSum is "<<currSum<<endl;
	if(currSum==target){
		ans.push_back(temp);
		return;
	}
// 	cout<<"printing ans "<<endl;
	for(int k=i;k<input.size();k++){
		if(target-currSum>=input[k]){
			temp.push_back(input[k]);
			helperfn(input,k+1,currSum+input[k],target,temp);
			temp.pop_back();
		}
	}
	return;
}

void findSubsets(vector<int>& input,int target){
	vector<int> temp;
	helperfn(input,0,0,target,temp);
// 	return ans;

}



int main(){

	vector<int> input;
	input.push_back(3);
	input.push_back(34);
	input.push_back(4);
	input.push_back(12);
	input.push_back(5);
	input.push_back(2);

	findSubsets(input,9);
	for(int i=0;i<ans.size();i++){
		for(int j=0;j<ans[i].size();j++){
			cout<<ans[i][j]<<"  ";

		}
		cout<<endl;
	}
}