【发布时间】:2014-08-26 08:15:17
【问题描述】:
所以如果给我一个数组,比如
a = {1, 2, 3}
我们知道给定的子数组(包括不连续的)是(这代表幂集)
{1} {2} {3} {1,2,3} {1,2} {1,3} {2,3}
我也知道这些子集可以用二进制计数来表示
000 -> 111 (0 to 7), where each 1 bit means we 'use' this value from the array
e.g. 001 corresponds to the subset {3}
我知道这种方法可以以某种方式用于生成所有子集,但我不确定如何在 c++ 中实现它
所以基本上我要问的是如何(如果可以的话)二进制计数来生成幂集?
也非常感谢任何其他生成幂集的方法!
【问题讨论】:
标签: c++ binary counting powerset