小编cot*_*o34的帖子

使用二进制计数对数组的所有子集进行计数

所以如果给我一个数组如

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 ++中实现

因此,基本上,我要问的是如何(如果可以的话)使用二进制计数来生成功率集?

任何其他用于生成功率集的方法也将不胜感激!

c++ binary counting powerset

0
推荐指数
1
解决办法
2067
查看次数

标签 统计

binary ×1

c++ ×1

counting ×1

powerset ×1