| <p> |
| You live on a circular road, <strong>L</strong> metres in length. Any point on the road can be referred to by a real number <strong>x</strong> |
| (0 ≤ <strong>x</strong> < <strong>L</strong>), |
| the distance along the road clockwise from its Northmost point to that point (in metres). |
| </p> |
|
|
| <p> |
| Fortunately for you, this road is served by public transportation! There are <strong>N</strong> bus stops at distinct, integral points along the road. |
| </p> |
|
|
| <p> |
| Unfortunately for you, due to budget cuts exactly <strong>K</strong> of these <strong>N</strong> stops will soon be removed. |
| The group of <strong>K</strong> removed stops will be chosen uniformly at random from the set of all possible groups of <strong>K</strong> stops. |
| </p> |
|
|
| <p> |
| You'd like to calculate the expected distance you'll have to walk from a random point along the road, chosen uniformly at random from the interval [0, <strong>L</strong>), |
| to the nearest of the remaining <strong>N</strong> - <strong>K</strong> bus stops, in metres. |
| </p> |
|
|
|
|
| <h3>Input</h3> |
| <p> |
| Input begins with an integer <strong>T</strong>, the number of roads. |
| For each road, there is first a line containing the space-separated integers <strong>N</strong>, <strong>K</strong>, and <strong>L</strong>. |
| Then follows a line containing a string of length <strong>L</strong>. This string consists of only the characters '0' and '1'. |
| There is a bus stop at position <strong>x</strong> if and only if the (<strong>x</strong> + 1)th character of the string is '1'. |
| Exactly <strong>N</strong> of the characters will be '1'. |
| </p> |
|
|
|
|
| <h3>Output</h3> |
| <p> |
| For the <strong>i</strong>th road, print a line containing "Case #<strong>i</strong>: " followed by |
| the expected distance you'll have to walk from a random point to the nearest bus stop, in metres. You should output the exact answer modulo (10<sup>9</sup> + 7). |
| That is, if the exact answer is <strong>a</strong> / <strong>b</strong> |
| (where <strong>a</strong> and <strong>b</strong> are integers), you should output <strong>a</strong> * <strong>b</strong><sup>-1</sup> mod (10<sup>9</sup> + 7) |
| (where <strong>b</strong><sup>-1</sup> is the modular inverse of <strong>b</strong> mod (10<sup>9</sup> + 7)). |
| </p> |
|
|
|
|
| <h3>Constraints</h3> |
| <p> |
| 1 ≤ <strong>T</strong> ≤ 20 <br /> |
| 1 ≤ <strong>N</strong> ≤ 500,000 <br /> |
| 0 ≤ <strong>K</strong> < <strong>N</strong><br /> |
| 1 ≤ <strong>L</strong> ≤ 1,000,000 <br /> |
| </p> |
|
|
|
|
| <h3>Explanation of Sample</h3> |
| <p> |
| In the first case, the single existing stop will remain untouched. If your starting position is smaller than 1 or greater than 5, you'll walk clockwise to it, for a distance of between 0m and 4m. Otherwise, you'll walk counterclockwise to it, also for a distance of between 0m and 4m. As such, your expected distance to walk will be 2m. |
| </p> |
| <p> |
| In the third case, one of the stops will be removed at random. Whichever one is removed, your situation will be similar to that of the first case - the distance you'll have to walk will be uniformly distributed between 0m and 4m, for an expected distance of 2m. |
| </p> |
| <p> |
| In the fourth case, the exact answer is 3.15 or 63/20, which is 550000007 when taken modulo (10<sup>9</sup> + 7). |
| </p> |
|
|