Use a 3D array dp[i][j][t] to memoize the count of ways for substring s[i..j] to evaluate to t (0/1).
{ "s": "T|F&T" }
2
{ "s": "T^F|T" }
1
{ "s": "F|T^F" }
Sign in to Run Code and Submit