转自
https://www.cnblogs.com/heyuhhh/p/11585358.html
子集
1 for (int m = 0; m < (1 << n); m++) 2 dp[m] = f(m); 3 for (int i = 0; i < n; i++) { 4 for (int m = 0; m < (1 << n); m++) 5 if (m & (1 << i)) 6 dp[m] += dp[m & ~(1 << i)];
超集
理解了子集之后,将二进制掩码中的1 -> 0, 0 -> 1, 即可。
1 for(int j = 0; j < n; j++) 2 for(int i = 0; i < 1 << n; i++) 3 if(!(i >> j & 1)) f[i] += f[i ^ (1 << j)];