Cpp Solution || DFS
Intuition\n Describe your first thoughts on how to solve this problem. \nExplore both possibilities of a person, being good or bad and check if current arrangem
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nExplore both possibilities of a person, being good or bad and check if current arrangement is valid or not.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nStep 1: Call `dfs` function with `statements` vector and a string `st`.\nStep 2: Make current person a good person and call `dfs`.\nStep 3: Make current person a bad person and call `dfs` while backtracking.\nStep 4: Check if `st` is valid or not.\nStep 5: `solve` function will check if statement of a `goodPerson[i]` about `person[j]` is contradictory to `curr[j]`.\nStep 6: If it is contradictory then it is not a valid count.\nStep 7: If it is not contradictory then it is a valid count.\nStep 8: Return the `res`.\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```\nclass Solution {\npublic:\n    int res = 0, n = 0;\n\n    bool solve(string& st, vector<vector<int>>& statements)\n    {\n        for(int i=0;i<n;i++)\n        {\n            if(st[i] == \'1\')\n            {\n                for(int j=0;j<n;j++)\n                {\n                    if(statements[i][j] != 2 && statements[i][j] != st[j] - \'0\')\n                        return false;\n                }\n            }\n        }\n        return true;\n    }\n    void dfs(vector<vector<int>>& statements, string& st, int ind, int goodCount)\n    {\n        if(ind == n)\n        {\n            if(solve(st, statements))\n                res = max(res, goodCount);\n            return;\n        }\n        st.push_back(\'1\');\n        dfs(statements, st, ind + 1, goodCount + 1);\n\n        st.back() = \'0\';\n        dfs(statements, st, ind + 1, goodCount);\n\n        st.pop_back();\n    }\n    int maximumGood(vector<vector<int>>& statements) {\n        n = statements.size();\n        string st = "";\n        dfs(statements, st, 0, 0);\n        return res;\n    }\n};\n```
['C++']