-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleetcode.cpp
More file actions
33 lines (33 loc) · 787 Bytes
/
leetcode.cpp
File metadata and controls
33 lines (33 loc) · 787 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include<bits/stdc++.h>
using namespace std;
void help(vector<int> &arr,int &count,int sum,int target,int index,vector<vector<int>> &res,vector<int> &res1){
if(sum==target){
res.push_back(res1);
count++;
return ;
}
else if(sum>target || index==int(arr.size())) return ;
for (int i=index;i<int(arr.size());i++){
res1.push_back(arr[i]);
help(arr,count,sum+arr[i],target,i,res,res1);
res1.pop_back();
}
}
int main(){
vector<int> arr={2,2,3,7};
int count=0;
vector<vector<int>> res;
vector<int> res1;
help(arr,count,0,7,0,res,res1);
set<vector<int>> set1;
for (auto it:res){
set1.insert(it);
}
for (auto it=set1.begin();it!=set1.end();it++){
for (auto it1:(*it)){
cout<<it1<<" ";
}
cout<<endl;
}
// cout<<count<<endl;
}