Hiring process8 levels
  1. 1 IQ Test
  2. 2 Additional Online Test (If Required)
  3. 3 Office Interview with Hiring Manager
  4. 4 Unpaid Test Task (Motivation Check)
  5. 5 Paid Test Task and Follow-Up Interview
  6. 6 Iterative Paid Test Tasks
  7. 7 Office Verification
  8. 8 Final Interview with the Founder

Problems > Boolean Parenthesization

Boolean Parenthesization

Difficulty: 2000 6000 ms 128 MB

dp interval-dp

Given a boolean expression of T/F literals joined by the operators &, |, ^, count the number of ways to fully parenthesize it so that it evaluates to True, modulo 109+7.

Input: one line: the expression, e.g. T^F&T.

Output: the number of True-yielding parenthesizations mod 109+7.

Constraints:

  • number of literals between 1 and 200

Sample Tests

Input 1
T^F&T
Output 1
2
Input 2
T
Output 2
1
Input 3
F
Output 3
0
Input 4
T|F
Output 4
1

Read the Editorial Statistics

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.
Ctrl+Enter submit · Ctrl+Space autocomplete · F11 fullscreen