方法1:permutation
int a[100];
……
for(int k=1; k<=n; k++) //从n选1 到 n选n
{
int b[21]= {0};
for(int i=1; i<=k; i++) b[i]=1; // 做一个b数组,放入k个1
do
{
for(int j=1; j<=n; j++) // 输出每个子集
{
if(b[j]==1)
cout<<a[j]<<" ";
}
cout<<endl;
}
while(prev_permutation(b+1,b+n+1)); // 全排列枚举b数组
}