1 条题解
-
0
记 为只在前 个观测点内观测集合 内所有星星所需要的最小观测次数,然后可以做类似背包的状压 DP,时间复杂度为 ,空间复杂度为 ,其中 为星星个数。
#include <bits/stdc++.h> using namespace std; const int N = 100 + 12, M = (1 << 20) + 12, K = 20; int c[M], d[N]; int main() { memset(c, 0x3f, sizeof c); int n; cin >> n; for (int i = 1; i <= n; i++) { int a, b = 0, e; cin >> a; while (a--) { cin >> e; b |= 1 << (e - 1); } d[i] = b; } c[0] = 0; for (int i = 1; i <= n; i++) for (int j = 0; j < (1 << K); j++) c[j | d[i]] = min(c[j | d[i]], c[j] + 1); for (int i = (1 << K) - 1; i >= 0; i--) if (c[i] <= 1e9) { cout << c[i] << endl; return 0; } return 0; }
信息
- ID
- 275
- 时间
- 1000ms
- 内存
- 512MiB
- 难度
- 7
- 标签
- 递交数
- 7
- 已通过
- 2
- 上传者