From d8e347f8abdecde7e195f723ed2924144bd140cd Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Sat, 10 Sep 2022 22:19:33 +0800 Subject: [PATCH] =?UTF-8?q?P3622=20[APIO2007]=20=E5=8A=A8=E7=89=A9?= =?UTF-8?q?=E5=9B=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.luogu.com.cn/record/86311624 --- Luogu/P3622/P3622.cpp | 59 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 Luogu/P3622/P3622.cpp diff --git a/Luogu/P3622/P3622.cpp b/Luogu/P3622/P3622.cpp new file mode 100644 index 00000000..304afbf9 --- /dev/null +++ b/Luogu/P3622/P3622.cpp @@ -0,0 +1,59 @@ +#include +#include +#include + +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::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; +}