#P7386. Trie Nodes Count from Non‐adjacent Ones Strings
Trie Nodes Count from Non‐adjacent Ones Strings
Trie Nodes Count from Non‐adjacent Ones Strings
Consider the following problem. We are given two nonnegative integers and such that we have exactly copies of and copies of . You are to arrange all these digits to form a binary string of length subject to the following conditions:
- The first character is .
- The last character is .
- No two 's are adjacent.
Let be the set of all strings (if any) satisfying the above conditions. Now, insert every string in into a 0-1 trie (a tree structure in which each node stores a character, either or ). We do not count the initial empty node; only nodes representing a character are counted. Your task is to determine the number of nodes in the trie built from .
Note: Since the answer for some instances might be very large and there may be many queries, for each query compute the answer modulo (which is prime) and then output the bitwise XOR (i.e. ^ in many languages) of all these modulo results. The final XOR is not taken modulo .
Explanation: A valid string $T$ of length $L=n+m$ must satisfy
[ T_1=0, \quad T_L=1, \quad \text{and for every } 1 \le i < L,; T_i=1 ;\Rightarrow; T_{i+1}=0. ]
All valid strings in are inserted into a trie. A node is created for every distinct nonempty prefix that appears in at least one string in . Your task is to count these nodes.
Input/Output format: See below.
inputFormat
The first line contains an integer T (T > 2) indicating the number of test cases.
Each of the following T lines contains two integers n and m separated by a space, representing the number of 1's and 0's respectively. It is guaranteed that at least one valid string can be constructed.
outputFormat
Output a single integer — the XOR (bitwise exclusive‐or) of the answers for all test cases, where for each test case the answer is the number of nodes in the trie (built from all valid strings) taken modulo 18888913.
sample
3
1 1
2 3
3 4
11
</p>