Wheel
Time limit2sMemory limit256 MB
Each city on a wheel graph is captured by one of two parties at random; find the expected size of the largest connected group of cities held by a single party.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Probability, Combinatorics, Graph
- Solved
- No attempts yet
Problem
The country in this problem has a rather interesting road system. There are cities in total: the capital and ordinary cities. All ordinary cities lie on a circle centered at the capital. The distance between any two neighboring ordinary cities is the same. Every city is connected by roads to its two neighbors and to the capital. Viewed from above, the country looks like a regular -gon whose vertices are connected to the center.
Two equally strong opposition parties want to seize power in this country. Nobody wants to do it peacefully! For safety, each city holds one tank platoon. Exactly at the start of the next day the following happens. In each city (including the capital), one of the opposition parties seizes power with equal probability. That party takes control of the tank platoon stationed in that city. Then each party plans to gather an army of the largest possible size in one place. A tank platoon can drive along a road only if both cities that the road connects are captured by the same party.
You organize an underground movement that also wants to seize power. You need to find the expected value of the largest number of tank platoons that can end up in one city. Do not let your organization down!
For example, suppose there are three ordinary cities. Then all four cities (three ordinary cities and the capital) are pairwise connected by roads. With probability the same party captures all cities. In this case the maximum army size is 4. With probability , two cities are captured by one party and two by the other. In this case the maximum army size is 2. Finally, with probability , one party seizes power in one city and the other party in the other three. In this case the maximum army size is 3. The expected value of the answer here is .
Input
The first line contains a positive integer , the number of test cases. The next lines each contain a single integer (), the number of ordinary cities in the country. The total number of ordinary cities over all test cases does not exceed 1000.
Output
For each test case, output a single number: the expected value of the largest number of platoons that can end up in one city. An answer is accepted if it differs from the correct one by at most .