Last active
August 29, 2015 14:20
-
-
Save jatindhankhar/12f156291e7cd620ed1b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# include <bits/stdc++.h> | |
using namespace std; | |
//template<typename T> | |
void print_power_set(const auto &vec,int n) | |
{ int sum = 0; | |
long int power_size = (1 << n); | |
for(long int counter=1; counter < power_size ; counter++) | |
{ | |
vector<int> subset; | |
for(int j=0;j<n;j++) | |
{ | |
if(counter & (1<<j)) | |
//cout<<vec[j]<<" "; | |
subset.push_back(vec[j]); | |
} | |
//cout<<endl; | |
auto res = minmax_element(begin(subset),end(subset)); | |
sum = sum + (*res.second - *res.first); | |
} | |
cout<<sum<<"\n"; | |
} | |
int main() | |
{ | |
ios_base::sync_with_stdio(false); | |
cin.tie(false); | |
int t; | |
cin>>t; | |
while(t--) | |
{ | |
int n; | |
cin>>n; | |
vector<int> v(n); | |
for(auto &i : v) | |
cin>>i; | |
print_power_set(v,n); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment