Dedenne
Time limit5sMemory limit512 MB
Find the minimum memorization cost of n prefix-free binary codewords with no two adjacent 0s, where each prefix's cost depends on how many codewords it covers.
- Level
Hard8 of 10
- Topics
- Tree, Dynamic programming, Greedy
- Solved
- No attempts yet
Problem
Have you ever heard about the famous Dedenne antennas? They allow Dedenne to communicate with each other even when they are miles and miles apart. However, Dedenne suspects that they do not communicate in an optimal way. That is why Dedenne came to you to optimize their language.
The language used by Dedenne consists of words. To transmit a word, Dedenne first uses a memorized dictionary to convert the word into a non-empty binary string (a codeword), and then transmits that string. The recipient receives the sequence and uses the same dictionary to recover the word. To preserve the correctness of the transmission, no two codewords in the dictionary may be equal, and no string may be a prefix of any other string.
Because of the peculiar nature of Dedenne, codewords are not allowed to have two consecutive 0 bits. When transmitted, two consecutive 0 bits merge into and hang up the transmitter indefinitely.
The dictionary is quite painful to memorize. Formally, let be the cost of a binary string . If is a prefix of exactly codewords, then The cost to memorize the dictionary is the sum of over all binary strings that are a prefix of at least one codeword.
For example, take the dictionary with 4 codewords: 0, 10, 110, 111. The cost of memorizing it is . Here denotes the empty string.
What is the minimum possible cost of memorizing a dictionary of words?
Input
The first line contains a single integer (), the number of independent test cases. Each of the following lines contains one integer (), the number of words Dedenne needs to memorize.
Output
For each test case, output a single integer: the minimum cost of a dictionary of words.
Hint
Here is a dictionary that might be used by Dedenne for to minimize the cost of memorizing.
