C++ || BitMask || Enumeration
Intuition\n Describe your first thoughts on how to solve this problem. \nLet\'s generate each and every combination of good and bad people and check if that com
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nLet\'s generate each and every combination of good and bad people and check if that combination is valid or not depending upon the statements matrix given.\n\nNow to efficiently generate, store and check these combinations we will use bitmasking\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nGenerate all the masks from 0 to 2^n - 1, representing all the combinations of good and bad (1 represents good, 0 represents bad)\n\nNow use two nested loops to check if current mask is valid or not\n\nIf it is valid then count the number of set bits and update the answer if it is more than the previous answer\n\n# Complexity\n- Time complexity: $$O(2^n * n^2)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int maximumGood(vector<vector<int>>& s) {\n        int n = s.size();\n        int ans = 0;\n        for(int mask = 0; mask < (1<<n); mask++){\n            int flag = 1;\n            // checking validity of the mask\n            for(int p1 = 0; p1 < n; p1++){\n                if(!(mask & (1<<p1))) continue;\n                for(int p2 = 0; p2 < n; p2++){\n                    if((mask & (1<<p2)) && s[p1][p2] == 0 || !(mask & (1<<p2)) && s[p1][p2] == 1){\n                        flag = 0;\n                        break;\n                    }\n                }\n                if(!flag) break;\n            }\n            if(flag) ans = max(ans, __builtin_popcount(mask));\n        }\n        return ans;\n    }\n};\nauto speedup = [](){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); return 0; }();\n```
['Array', 'Bit Manipulation', 'Enumeration', 'C++']