![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1.空集: 0 2.只含有第i个元素的集合{i}: 1<<i; 3.含有全部n个元素的集合{0,1,…,n-1}: (1<<n)-1 4.判断第i个元素是否属于集合S: if (S>>i & 1) 5.向集合中加入第i个元素S∪{i}: S | (1<<i) 6.从集合中去除第i个元素S{i}: S & ~(1<<i) 7.集合S和T的并集S∪T: S|T 8.集合S和T的交集S∩T: S&T
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
for (int S = 0 ; S < 1 << n; S++ ) { // 对子集的处理 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
int sub = sup; do { // 对子集处理 sub = (sub-1) & sup; } while(sub != sup); // 处理完之后 会有 -1&sup = sup
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
int comb = (1 << k) -1; while ( comb < 1 << n ) { // 对大小为k的集合的处理 int x = comb & -comb; int y = comb + x; comb = ((comb & ~y) / x >> 1) | y; }