Skip to content

Commit 3debdf2

Browse files
Merge pull request #383 from yashagarwal1999/master
Solved Issue Combinations #381 as powerset.cpp
2 parents b4da9ad + c959426 commit 3debdf2

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#include<bits/stdc++.h>
2+
#define endl "\n"
3+
#define pb push_back
4+
#define mp make_pair
5+
#define fi first
6+
#define se second
7+
#define MOD 1000000007
8+
#define MOD9 1000000009
9+
#define pi 3.1415926535
10+
#define ms(s, n) memset(s, n, sizeof(s))
11+
#define prec(n) fixed<<setprecision(n)
12+
#define eps 0.000001
13+
#define all(v) v.begin(), v.end()
14+
#define allr(v) v.rbegin(), v.rend()
15+
#define forr(i,p,n) for(ll i=p;i<n;i++)
16+
#define MAXN 500003
17+
typedef long long ll;
18+
inline ll mod(ll x,ll n)
19+
{
20+
if(x<n)
21+
{
22+
return x;
23+
}
24+
return x-n;
25+
}
26+
using namespace std;
27+
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
28+
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
29+
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n%p; n = n * n%p;} return r;}
30+
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
31+
ll inv_euclid(ll a, ll m = MOD){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}
32+
33+
34+
35+
int main(){
36+
37+
38+
ios_base::sync_with_stdio(false);
39+
cin.tie(0);
40+
cout.tie(0);
41+
vector<ll>v;
42+
ll sum=0,act=0,k,n,q,f;
43+
cin>>n;
44+
v.reserve(n);
45+
forr(i,0,n)
46+
{
47+
cin>>f;
48+
v.pb(f);
49+
50+
}
51+
ll x=(1LL<<n);
52+
vector<ll>arr[x];
53+
54+
forr(i,1,x)
55+
{
56+
for(ll j=0;j<n;j++)
57+
{
58+
ll p=(1LL<<j);
59+
if(i & p)arr[i].pb(v[j]);
60+
}
61+
}
62+
forr(i,1,x)
63+
{
64+
forr(j,0,arr[i].size())
65+
{
66+
cout<<arr[i][j]<<" ";
67+
}
68+
cout<<endl;
69+
}
70+
return 0;
71+
}

python/yashagarwal1999_powerset.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from itertools import chain, combinations
2+
3+
def powerset(iterable):
4+
s = list(iterable)
5+
return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))
6+
7+
print(list(powerset("abc")))

0 commit comments

Comments
 (0)