-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlec13_printalong.cpp
More file actions
42 lines (35 loc) · 920 Bytes
/
lec13_printalong.cpp
File metadata and controls
42 lines (35 loc) · 920 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
34
35
36
37
38
39
40
41
// localpc soln
#include<bits/stdc++.h>
using namespace std;
void subsequence(int arr[] , int index , int n ,vector<vector<int>>&ans , vector<int>&sumans , vector<int>&temp ,int sum)
{
if(index == n)
{
ans.push_back(temp);
sumans.push_back(sum);
return;
}
//not included
subsequence(arr , index+1 , n , ans , sumans , temp , sum);
temp.push_back(arr[index]);
//included
subsequence(arr , index+1 , n , ans ,sumans,temp, sum+=(arr[index]));
temp.pop_back();
}
int main()
{
int arr[] = { 1 , 2 , 3 , 4};
vector<vector<int>> ans ;
vector<int>sumans ;
vector<int>temp;
subsequence(arr , 0 ,4, ans ,sumans , temp , 0 );
for(int i = 0 ; i < ans.size() ; i++)
{
for(int j = 0 ; j < ans[i].size() ; j++)
{
cout<<ans[i][j]<<" ";
}
cout<<"-->"<<sumans[i]<<endl;
}
// cout<<endl;
}