枚举子集
zzr8178541919 · · 个人记录
非常漂亮的枚举子集的写法
有短又快!
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<map>
#include<queue>
#define reg register
#define int long long
using namespace std;
const int maxn=1e5+5;
inline int read()
{
int x=0,f=1;
char ch=getchar();
while(ch<'0' || ch>'9')
{
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0' && ch<='9')
{
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
signed main()
{
while(true)
{
int S;//输入集合
cin>>S;
for(int x=S;x;x=(x-1) & S)//x为子集
{
cout<<x<<" ";
}
cout<<endl;
}
return 0;
}
/*
3 3 5 4
1 4 6
*/