#include<bits/stdc++.h>
using namespace std;
void disp(vector<vector<int>> &ans) {
for(int i=0; i< ans.size(); i++) {
int sum =0;
for(int j=0; j<ans[i].size(); j++) {
cout<< ans[i][j] <<" ";
sum += ans[i][j];
}
cout<<" "<<sum;
cout<<endl;
}
}
//subsetSum(0, n/2,arr, layer, ans, sum);
void subsetSum(int i, int n,vector<int> &arr, vector<int> &layer, vector<vector<int>> &ans, int sum) {
if( i== n) {
ans.push_back(layer);
return;
}
//pick
layer.push_back(arr[i]);
sum+=arr[i];
subsetSum(i+1, n/2,arr, layer, ans, sum);
layer.pop_back();
sum = sum- arr[i];
subsetSum(i+1, n/2,arr, layer, ans, sum);
}
int main(){
vector<int> arr = {45, 34, 4, 12, 5, 23};
int n = sizeof(arr)/ sizeof(arr[0]);
cout<<n;
int sum =0;
vector<int> layer;
vector<vector<int>> ans;
subsetSum(0, n/2,arr, layer, ans, sum);
disp(ans);
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnZvaWQgZGlzcCh2ZWN0b3I8dmVjdG9yPGludD4+ICZhbnMpIHsKCWZvcihpbnQgaT0wOyBpPCBhbnMuc2l6ZSgpOyBpKyspIHsKCQlpbnQgc3VtID0wOwoJCWZvcihpbnQgaj0wOyBqPGFuc1tpXS5zaXplKCk7IGorKykgewoJCQljb3V0PDwgYW5zW2ldW2pdIDw8IiAiOwoJCQlzdW0gKz0gYW5zW2ldW2pdOwoJCX0KCQljb3V0PDwiICI8PHN1bTsKCQljb3V0PDxlbmRsOwoJfQp9Ci8vc3Vic2V0U3VtKDAsIG4vMixhcnIsIGxheWVyLCBhbnMsIHN1bSk7CnZvaWQgc3Vic2V0U3VtKGludCBpLCBpbnQgbix2ZWN0b3I8aW50PiAmYXJyLCB2ZWN0b3I8aW50PiAmbGF5ZXIsIHZlY3Rvcjx2ZWN0b3I8aW50Pj4gJmFucywgaW50IHN1bSkgewoJaWYoIGk9PSBuKSB7C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