-
Notifications
You must be signed in to change notification settings - Fork 3
/
1601.cpp
26 lines (26 loc) · 822 Bytes
/
1601.cpp
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
class Solution {
public:
vector<int> buildings;
bool check(int state, int n, int m, vector<vector<int>>& requests) {
for (int i = 0; i < n; ++i) buildings[i] = 0;
for (int i = 0; i < m; ++i) {
if (state & (1 << i)) {
buildings[requests[i][0]]++;
buildings[requests[i][1]]--;
}
}
for (int i = 0; i < n; ++i) {
if (buildings[i] != 0) return false;
}
return true;
}
int maximumRequests(int n, vector<vector<int>>& requests) {
int m = requests.size();
buildings.resize(n, 0);
int res = 0;
for (int state = 0; state < (1 << m); ++state) {
if (check(state, n, m, requests)) res = max(res, __builtin_popcount(state));
}
return res;
}
};