[C++] bitmask, O(2^N * N * N)
\nclass Solution {\npublic:\n    int countBits(int mask) {\n        int cnt = 0;\n        while(mask) {\n            cnt += mask & 1;\n            mask >>= 1;\n
```\nclass Solution {\npublic:\n    int countBits(int mask) {\n        int cnt = 0;\n        while(mask) {\n            cnt += mask & 1;\n            mask >>= 1;\n        }\n        return cnt;\n    }\n    int isGood(int mask, int i) {\n        return mask & (1 << i);\n    }\n    int maximumGood(vector<vector<int>>& statements) {\n        int n = statements.size();\n        int mask = 1 << n;\n        int ans = 0;\n        for(int s = mask - 1; s >= 0; --s) {\n            int isValid = true;\n            for(int i = 0; i < n; ++i) {\n                for(int j = 0; j < n; ++j) {\n                    if(isGood(s, i)) {\n                        if((statements[i][j] == 0 && isGood(s, j)) || (statements[i][j] == 1 && !isGood(s, j))) {\n                            isValid = false;\n                            break;\n                        }\n                    }\n                }\n                if(!isValid) break;\n            }\n            if(isValid) {\n                ans = max(ans, countBits(s));\n            }\n        }\n        return ans;\n    }\n};\n```
['C', 'Bitmask']