二进制枚举

//求一个集合的子集
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n=4;
    int a[4]={15,20,25,30};
    for(int i=0;i<(1<<n);i++)
    {
        printf("%d: ",i);
        for(int j=0;j<n;j++)
        {
            if(i&(1<<j))
            {
                printf("%d ",a[j]);
            }
        }
        puts("");
    }
    return 0;
}
原文地址:https://www.cnblogs.com/Ritchie/p/5424848.html