Atomic Computer
Time limit1sMemory limit256 MB
Count the length-y signed-binary strings over -1, 0 and 1 whose digits weighted by powers of two sum to x.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Bit manipulation
- Solved
- No attempts yet
Problem
A professor has built the Atomic Computer, which runs 8,000,000,000 times faster than a normal computer. It keeps values in a special memory where one bit represents one of three states, -1, 0 and 1.
Write the bits of a bit memory as , starting from the front. The value held by the memory is
Each is -1, 0 or 1. For example, holds . The number of bits is always exactly , and a representation whose leading bits are 0 counts as its own way of storing the value.
Given an integer to store and the number of bits , count the ways to store in bits.
Input
The first line contains the number of test cases . ()
Each of the next lines contains two integers and , where is the value to store and is the number of bits. (, )
Output
Print lines. The th line contains the number of ways to store in bits.