Python Bitmask Backtracking
Try to make each person good and bad but only if prior statements do not conflict, If there is a conflict we return early.\n\n```py\nclass Solution:\n    def ma
Try to make each person good and bad but only if prior statements do not conflict, If there is a conflict we return early.\n\n```py\nclass Solution:\n    def maximumGood(self, statements: List[List[int]]) -> int:\n        \n        maskGood = defaultdict(int)\n        maskBad = defaultdict(int)\n        \n        for i in range(len(statements)):\n            for j in range(len(statements[i])):\n                if statements[i][j] == 0:\n                    maskBad[i] |= (1 << j)\n                if statements[i][j] == 1:\n                    maskGood[i] |= (1 << j)\n        \n        \n        def dfs(i, good, bad):\n            \n            if i >= len(statements):\n                return 0\n            \n            res = float(\'-inf\')\n            #try each person good or bad\n            #if good all statements must line up\n            #if someone is good all statements should be recorded\n            bgood = good \n            bbad = bad\n            #take all statements as fact\n            bgood |= maskGood[i]\n            bbad |= maskBad[i]\n            \n            #check for conflicting statments\n            canbegood = (good & maskBad[i]) == 0 and (bad & maskGood[i]) == 0\n            \n\n            #can be good and is not already bad\n            if canbegood and bad & (1 << i) == 0:\n                #take statments as fact\n                res = max(res, dfs(i+1, bgood | (1 << i), bbad) + 1)\n            \n            #can be bad and is not already good\n            if good & (1 << i) == 0:\n                #no statements updated\n                res = max(res, dfs(i+1, good, bad | (1 << i)))\n        \n                      \n            return res\n            \n                      \n        return dfs(0, 0, 0)
['Backtracking', 'Bitmask', 'Python']