Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int N;
- cin >> N;
- vector < vector < string > > a(N, vector < string >(3));
- for(int i = 0; i < N; ++i)
- for(int j = 0; j < 3; ++j)
- cin >> a[i][j];
- int ans = 1;
- for(int mask = (1 << N); mask > 0; --mask) {
- unordered_map < string , bool > M;
- int s = __builtin_popcount(mask);
- if(s > ans) {
- bool ok = true;
- for(int i = 0; (1 << i) <= mask && ok; ++i)
- if(mask & (1 << i))
- for(int j = 0; j < 3 && ok; ++j)
- if(M[a[i][j]])
- ok = false;
- else
- M[a[i][j]] = true;
- if(ok)
- ans = s;
- }
- }
- cout << ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment