所以如果给我一个数组如
a = {1, 2, 3}
Run Code Online (Sandbox Code Playgroud)
我们知道给定的子数组(不连续)是(这表示幂集)
{1} {2} {3} {1,2,3} {1,2} {1,3} {2,3}
Run Code Online (Sandbox Code Playgroud)
我也知道这些子集可以通过从
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}
Run Code Online (Sandbox Code Playgroud)
我知道可以用某种方法生成所有子集,但是我不确定如何在c ++中实现
因此,基本上,我要问的是如何(如果可以的话)使用二进制计数来生成功率集?
任何其他用于生成功率集的方法也将不胜感激!