#P88. Special Judge Test 1: Memory Limit Exceeded
Special Judge Test 1: Memory Limit Exceeded
Person in charge
Problem Description
struct S
{
bool c[5012];
int dc[5012][2];
int ts = 1;
int x;
void init(int h)
{
memset(c, 0, sizeof c);
memset(dc, 0, sizeof dc);
c[1] = 0;
ts = 1;
x = h;
}
void add(int num)
{
int now = 1;
for (int i = 1, j = x; j >= 0; i++, j--)
{
bool cc = num & (1 << j);
int xx = ts + 1;
if (dc[now][cc]) xx = dc[now][cc];
if (xx > ts)
{
ts++;
dc[now][cc] = ts;
c[ts] = cc;
}
now = xx;
}
}
};
The above code implements a 01 Trie.
This 01 Trie can store any integer in the range via the add
function. After insertion, the value of variable ts
reflects the actual space used by this 01 Trie.
Your task is to insert integers from into such a 01 Trie to maximize its actual space usage.
Input Format
Multiple test cases.
The first line contains a positive integer , indicating the number of test cases.
Each of the next lines contains two positive integers and .
Output Format
For each test case, output one line containing integers from , representing the integers you insert.
Sample
6
1 1
1 2
2 1
2 2
2 3
2 4
1
0 1
0
1 2
3 0 1
2 3 0 1
Sample Explanation
The ts
values for the 6 test cases are respectively.
Note: The solution is not unique.
Constraints