2020-08-09 提高組模擬賽選講
阿新 • • 發佈:2020-08-19
Problem T1. 雷神領域
生成新的點的性質是兩個座標都已經配對過,也就是在同一個連通塊中。
考慮並查集維護,每次將。
時間複雜度 \(\mahthcal O(n^2)\)
#include <bits/stdc++.h> using namespace std; const int _max = 5000; int fa[10005]; int dp[5005][5005]; int n; int get(int x) { return fa[x] == x ? x : fa[x] = get(fa[x]); } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= 10000; ++i) fa[i] = i; for (int i = 1, x, y; i <= n; ++i) { cin >> x >> y; int p = get(x), q = get(y + _max); if (p != q) { fa[p] = q; } } dp[0][0] = 0; for (int i = 1; i <= _max; ++i) for (int j = 1; j <= _max; ++j) if (get(i) == get(j + _max)) { dp[i][j] = dp[i - 1][j - 1] + 1; } else { dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]); } cout << dp[_max][_max] << '\n'; return 0; }
Problem T2. 密碼鎖
和啟智樹暑假集訓的一道題相似,考慮對於原序列每一個元素和前一個元素異或一下,