斯特林反演
斯特林数
第一类斯特林数:将
第二类斯特林数:将
我们有以下递推式:
形式一:前缀和型
正变换:若数列
则:
其中
形式二:后缀和型
正变换:若数列
则:
组合意义:
P10591
对于
定义
首先考虑将所有点分进
因此,我们可以得到正变换:
于是,通过斯特林反演可以得到:
所以答案就是:
现在考虑求出
假设有
这样,我们就得到了一个异或方程组,而
所以就有:
由于
#include <bits/stdc++.h>
#define N 10005
using namespace std;
using LL = long long;
LL n, m, b[N], c, a[N], f[N], s;
bool e[N][15][15];
void I(LL x) {
for (int i = 63; i >= 0; i--) {
if (x >> i & 1) {
if (!b[i]) {
b[i] = x, c++;
break;
}
x ^= b[i];
}
}
}
void S(int x, int w) {
if (x > n) {
fill(b, b + 64, c = 0);
for (int y = 1; y <= n; y++) {
for (int z = y + 1; z <= n; z++) {
if (a[y] != a[z]) {
LL k = 0;
for (int i = 1; i <= m; i++) {
(e[i][y][z]) && (k |= (1LL << (i - 1)));
}
I(k);
}
}
}
s = (s + (w & 1 ? 1 : -1) * f[w - 1] * (1LL << (m - c)));
return;
}
for (int i = 1; i <= w + 1; i++) {
a[x] = i;
S(x + 1, max(i, w));
}
}
int main() {
cin.tie(0)->sync_with_stdio(false);
cin >> m;
for (int i = 1; i <= m; i++) {
string t;
cin >> t;
for (; n * (n - 1) / 2 < t.size(); n++) {
}
for (int x = 1, j = 1; x <= n; x++) {
for (int y = x + 1; y <= n; y++, j++) {
e[i][x][y] = e[i][y][x] = t[j - 1] - '0';
}
}
}
for (int i = f[0] = 1; i <= n; i++) {
f[i] = f[i - 1] * i;
}
S(1, 0);
cout << s;
return 0;
}