5
int maximumGood(vector<vector<int>> &statements) {8
dfs(statements, cur, 0, 0);12
void dfs(vector<vector<int>> &statements, string &cur, int index, int goodPersonCount) {14
// Check if cur is valid15
if (isValid(cur, statements)) result = max(goodPersonCount, result);19
// Make current person a good person and call DFS21
dfs(statements, cur, index + 1, goodPersonCount + 1);23
// Backtrack: Make current person a bad person and call DFS25
dfs(statements, cur, index + 1, goodPersonCount);30
bool isValid(string &cur, vector<vector<int>> &statements) {31
// isValid() will check if the statement of goodPerson (i) about person (j)32
// i.e. statement[i][j], is contradictory to what we have in cur[j]34
// If it is contradictory, then in terms of question i is lying, and is not35
// a goodPerson, so this is not a valid count.37
// If s[i][j] == 2, i.e. person i said nothing about j, then we can skip it.38
for (int i = 0; i < n; i++) {39
if (cur[i] == '1') { // We only care about what good people say40
// Now we check what they said is in accordance with what we have in cur41
for (int j = 0; j < n; j++) {42
if (statements[i][j] != 2 && statements[i][j] != cur[j] - '0') return false;47
// All statements made by good person is in accordance with cur, so we have48
// a valid count of good people