Overview
This is a classic Interval DP problem. We evaluate every possible substring and partition it into left and right sub-expressions.
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Find the number of ways to parenthesize a boolean expression so that it evaluates to True.
This is a classic Interval DP problem. We evaluate every possible substring and partition it into left and right sub-expressions.
Because operators like XOR (`^`) need both True and False values to produce True, we must track the number of ways to evaluate to both True and False.
For a substring from `i` to `j`, we iterate a split point `k` on the operators. The total combinations come from multiplying the left ways and right ways.
By splitting at the operator, we reduce the problem to two smaller, independent problems. The results are combined based on the truth table of the operator.