加括号
https://practice.geeksforgeeks.org/problems/boolean-parenthesization/0
Given a boolean expression with following symbols.
Symbols
‘T’ —> true
‘F’ —> false
And following operators filled between symbols
Operators
& —> boolean AND
| —> boolean OR
^ —> boolean XOR
Count the number of ways we can parenthesize the expression so that the value of expression evaluates to true.
For Example:
The expression is “T | T & F ^ T”, it evaluates true
in 4 ways ((T|T)&(F^T)), (T|(T&(F^T))), (((T|T)&F)^T)
and (T|((T&F)^T)).
dp[ i ][ j ][ 0/1 ] 表示字符 i - j 区间内取 true 的个数和取 false 的个数。状态转移: dp[ i ][ j ][ ? ] += dp[ i ][ h ][ ? ] * dp[ h+1 ][ j ][ ? ], 其中 “ ?”根据具体情况而定。
按照字符长度由下向上。
1 |
|