Untitled
unknown
c_cpp
7 months ago
1.7 kB
12
Indexable
#include <bits/stdc++.h> using namespace std; #define ll long long int tt, tc; int tiles[7][7], n; pair<int, int> given[28]; pair<int, int> norm(int a, int b) { if (a > b) swap(a, b); return make_pair(a, b); } int dp[28][7][7]; int valid(int i, int x, int y) { if (i == n) { for (int j = 0; j < 7; j++) for (int k = 0; k < 7; k++) if (!tiles[j][k]) { if (j == x || j == y || k == x || k == y) return 1; } return 0; } int& ret = dp[i][x][y]; if (ret != -1) return ret; int a = given[i].first, b = given[i].second; vector<pair<int, int>> to_states; if (a == x) to_states.push_back(norm(b, y)); if (a == y) to_states.push_back(norm(b, x)); if (b == x) to_states.push_back(norm(a, y)); if (b == y) to_states.push_back(norm(a, x)); sort(to_states.begin(), to_states.end()); to_states.erase(unique(to_states.begin(), to_states.end()), to_states.end()); assert((int)to_states.size() <= 2); ret = 0; for (auto& [xx, yy] : to_states) ret = ret | valid(i + 1, xx, yy); return ret; } void solve() { memset(dp, -1, sizeof(dp)); cin >> n; for (int i = 0; i < n; i++) { cin >> given[i].first >> given[i].second; } for (int i = 0; i < n; i++) { int x = given[i].first, y = given[i].second; tiles[x][y] = tiles[y][x] = 1; } if (n == 1) { cout << "Yes\n"; return; } auto p = norm(given[0].first, given[0].second); cout << (valid(1, p.first, p.second) ? "Yes\n" : "No\n"); } int main() { ios::sync_with_stdio(0); cin.tie(0); tt = 1, tc = 1; // cin >> tt; while (tt--) { solve(); tc++; } }
Editor is loading...
Leave a Comment