N diamonds fall onto a pile and slide left or right at random, and you compute the probability that one stops exactly at the given spot.
Medium6ProbabilitySimulationDynamic programmingNo attempts yetTime limit5sMemory limit512 MBDiamonds are falling from the sky. People are buying up the spots where a diamond might land, just to own a diamond if one lands there. You have been offered such a spot, and you want to know whether the offer is good.
Diamonds are shaped like diamonds: the diamond with center (X,Y) is the square with vertices (X−1,Y), (X,Y+1), (X+1,Y) and (X,Y−1). Every diamond lies in the XY plane. X is the horizontal direction and Y is the vertical direction. The ground is at Y=0, and positive Y coordinates are above the ground.
The diamonds fall one at a time along the Y axis. Each one starts at (0,Y) for a very large Y and falls straight down until it hits the ground or another diamond.
A diamond that hits the ground sinks until its center reaches Y=0, then stops. So a diamond whose center is at height 0 never falls or slides any further.
A diamond that hits another diamond vertex to vertex can start sliding down without turning, in one of two directions: down and left, or down and right. If no diamond immediately blocks either side, it slides left or right with equal probability. If a diamond blocks one side, the falling diamond slides to the other side, and it keeps sliding until another diamond blocks it or it becomes buried in the ground. If diamonds block both the left and the right path, the diamond stops where it is.

Look at the example in the picture. The first diamond hits the ground and stops half buried, with its center at (0,0). The second diamond picks left or right with equal probability. Here it went left and stopped buried in the ground next to the first diamond, at (−2,0). The third diamond also hits the first one. Sliding right buries it in the ground, and sliding left leaves it above and between the two diamonds already placed. Here it went left again and stopped at (−1,1). The fourth diamond has nothing to choose. It slides right and ends up buried in the ground at (2,0).
The first line contains the number of test cases T. Each of the next T lines contains three integers N, X and Y: the number of falling diamonds, and the position of the spot you are interested in. The spot you are interested in buying does not have to be at or near the ground.
Limits
For each test case print one line in the form Case #x: p, where x is the test case number starting from 1 and p is the probability that one of the N diamonds stops with its center exactly at (X,Y). Print p rounded to six digits after the decimal point.