int ans = 0;//计蒜客的课程,侵删。
for (int i = 0; i < (1<<14); ++i) {//枚举1-(1<<14)的所有情况
int tot_1 = 0;
int tot_0 = 0;
int num = 2;
for (int j = 0; j < 14; ++j) {
if (i&(1 << j)) { // 这里判断二进制 i 从右数第 j + 1 位是否为 1
tot_1++;
num = num * 2;
} else {
tot_0++;
num = num - 1;
}
}
if (tot_1 == 5 && tot_0 == 9 && num == 1) {
++ans; // 记录合法方案数
}
}
二进制枚举子集(计蒜客)
最新推荐文章于 2022-06-17 08:08:18 发布