0%

AtCoder Beginner Contest 190 C题(二进制枚举)

题目链接

官方题解

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

int n, m;

int main() {
cin >> n >> m;
vector<pair<int, int> > cond(m);
for(auto & [A, B] : cond) cin >> A >> B;
int k;
cin >> k;
vector<pair<int, int> > choice(k);
for(auto & [C, D] : choice) cin >> C >> D;
int ans = 0;
for(int bit = 0; bit < 1<<k; bit++) {
vector<bool> ball(n);
for(int i = 0; i < k; i++) {
const auto [C, D] = choice[i];
ball[bit& 1<<i ? C:D];
}
int cnt = 0;
for(auto [A, B] : cond) {
if(ball[A] && ball[B]) cnt++;
}
if(ans < cnt) ans = cnt;
}
printf("%d\n", ans);

return 0;
}
求大佬赏个饭