枚举
排列
全排列
void AllPermutation(int l, int r)
{
vector<int>p;
for (int i = l; i <= r; ++i)
{
p.push_back(i);
}
do
{
//do something
} while (next_permutation(p.begin(), p.end()));
}
子集
枚举全部子集
void AllSubset(int s)
{
for (int i = s; i; i = (i - 1) & s)
{
//do something
}
}
枚举k大小子集
void GospersHack(int k, int n)
{
int cur = (1 << k) - 1, limit = (1 << n);
while (cur < limit)
{
// do something
int lb = cur & -cur, r = cur + lb;
cur = (((r ^ cur) >> 2) / lb) | r;
}
}
标签:do,排列,int,void,枚举,子集
From: https://www.cnblogs.com/ProtectEMmm/p/18360925