0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-08 17:38:47 +00:00

P3226 [HNOI2012]集合选数

https://www.luogu.com.cn/record/102434789
This commit is contained in:
Baoshuo Ren 2023-02-18 17:28:35 +08:00
parent 0cfa7fdef7
commit 141a85eb62
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

76
Luogu/P3226/P3226.cpp Normal file
View File

@ -0,0 +1,76 @@
#include <iostream>
#include <algorithm>
#include <cstring>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1e5 + 5,
M = 20;
const int mod = 1e9 + 1;
int n, g[M][M], w[M], f[2][(1 << M) + 5],
ans = 1;
bool vis[N];
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int x = 1; x <= n; x++) {
if (vis[x]) continue;
// === Build ===
int height = 0,
width = 0;
for (int i = x; i <= n; i *= 2) {
height++;
w[height] = 0;
for (int j = i; j <= n; j *= 3) {
vis[j] = true;
w[height]++;
}
width = std::max(width, w[height]);
}
// === DP ===
f[0][0] = 1;
for (int i = 1, k = 1; i <= height; i++, k ^= 1) {
for (int s = 0; s < 1 << width; s++) {
f[k][s] = 0;
}
for (int s = 0; s < 1 << w[i]; s++) {
if ((s & (s << 1)) == 0) {
for (int t = 0; t < 1 << w[i - 1]; t++) {
if ((s & t) == 0 && (t & (t << 1)) == 0) {
f[k][s] = (f[k][s] + f[k ^ 1][t]) % mod;
}
}
}
}
}
int res = 0;
for (int s = 0; s < 1 << width; s++) {
res = (res + f[height & 1][s]) % mod;
}
ans = static_cast<long long>(ans) * res % mod;
}
cout << ans << endl;
return 0;
}