0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 18:28:47 +00:00

P3622 [APIO2007] 动物园

https://www.luogu.com.cn/record/86311624
This commit is contained in:
Baoshuo Ren 2022-09-10 22:19:33 +08:00
parent e0ae2db0e2
commit d8e347f8ab
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

59
Luogu/P3622/P3622.cpp Normal file
View File

@ -0,0 +1,59 @@
#include <iostream>
#include <algorithm>
#include <limits>
using namespace std;
const int N = 1e4 + 5,
C = 5e4 + 5,
M = (1 << 5) + 5;
int n, c, a[C][M], f[N][M], ans;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> c;
for (int i = 1, e, f, l; i <= c; i++) {
cin >> e >> f >> l;
int fear = 0;
for (int j = 1, x; j <= f; j++) {
cin >> x;
fear |= (1 << (x - e + n) % n);
}
int like = 0;
for (int j = 1, y; j <= l; j++) {
cin >> y;
like |= (1 << (y - e + n) % n);
}
for (int j = 0; j < 1 << 5; j++) {
if ((like & j) || (fear & ~j)) a[e][j]++;
}
}
for (int s = 0; s < 1 << 5; s++) {
std::fill_n(f[0], M, std::numeric_limits<int>::min());
f[0][s] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < 1 << 5; j++) {
f[i][j] = max(f[i - 1][(j & 0b1111) << 1], f[i - 1][(j & 0b1111) << 1 | 1]) + a[i][j];
}
}
ans = std::max(ans, f[n][s]);
}
cout << ans << endl;
return 0;
}