1 条题解
-
0
使用状态压缩动态规划来找到最大美观度,状态
mask表示已使用的位置,dp[mask]记录当前最大美观度,遍历所有可能的位置分配,更新状态转移,最终得到最大美观度。AC code:
#include <bits/stdc++.h> using namespace std; void pre(const vector<int> &a, unordered_map<int, vector<int>> &pos) { for (int i = 0; i < a.size(); ++i) { pos[a[i]].push_back(i); } } bool issub(const vector<int> &a, const vector<int> &b, const unordered_map<int, vector<int>> &pos) { int pinx = -1; for (int num : b) { const auto &poss = pos.at(num); auto it = lower_bound(poss.begin(), poss.end(), pinx + 1); if (it == poss.end()) { return false; } pinx = *it; } return true; } int main() { freopen("ds.in", "r", stdin); freopen("ds.out", "w", stdout); int n, q; cin >> n >> q; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } unordered_map<int, vector<int>> pos; pre(a, pos); for (int i = 0; i < q; ++i) { int op; cin >> op; if (op == 1) { int l, r, v; cin >> l >> r >> v; for (int j = l - 1; j < r; ++j) { a[j] = v; } pos.clear(); pre(a, pos); } else { int m; cin >> m; vector<int> b; for (int j = 0; j < m; ++j) { int x, y; cin >> x >> y; for (int k = 0; k < y; ++k) { b.push_back(x); } } if (issub(a, b, pos)) { cout << "Yes" << endl; } else { cout << "No" << endl; } } } return 0; }
- 1
信息
- ID
- 150
- 时间
- 2000ms
- 内存
- 512MiB
- 难度
- 3
- 标签
- 递交数
- 5
- 已通过
- 3
- 上传者