Posted on

Description

Submission

class Solution {
    int m;
    bool check(int state, vector<vector<int>>& requests, int n) {
        vector<int> building(n, 0);

        for(int i = 0; i < m; ++i) {
            if((state>>i)&1) {
                building[requests[i][0]]--;
                building[requests[i][1]]++;
            }
        }

        for(int i = 0; i < n; ++i) {
            if(building[i]) return false;
        }
        return true;
    }
public:
    int maximumRequests(int n, vector<vector<int>>& requests) {
        m = requests.size();
        int ret = 0;
        
        for(int state = 0; state < (1 << m); ++state) {
            if(check(state, requests, n)) {
                ret = max(ret, __builtin_popcount(state));
            }
        }

        return ret;
    }
};

References

  1. https://www.youtube.com/watch?v=jOI8_U-aenY

Leave a Reply

Your email address will not be published. Required fields are marked *