原题链接
状压dp
①枚举j为i的非空子集:
for (int i = 1; i < (1 << n); ++i) for (int j = i; j; j = (j - 1) & i)
代码如下:
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 0; char ch = getchar();
while (!isdigit(ch)) f = ch == '-', ch = getchar();
while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
return f ? -x : x;
}
const int N = 12, inf = 0x3f3f3f3f;
int n, m, g[1 << N], d[