|
<p> |
|
Kit is competing on the popular game show, Fortunate Wheels. On this show, there is a secret word <b>S</b> consisting only of uppercase letters, known only to the host. Contestants can pay points to buy sequences of letters in hopes of matching part of S and earning more points! This show is clearly a scam, as the probability of earning more points than are spent is extremely low. Fortunately, Kit has come prepared -- he knows the secret word! Even so, getting as many points as possible will not be easy. |
|
</p> |
|
|
|
<p> |
|
There are <b>N</b> <i>basic deals</i> which contestants can take. The <i>i</i>th deal costs <b>A<sub>i</sub></b> points, and allows the contestant to purchase any sequence of <b>B<sub>i</sub></b> letters. Furthermore, deals can be combined to purchase longer sequences! Combining a deal with cost <b>C<sub>1</sub></b> and length <b>L<sub>1</sub></b> with another deal (potentially the same one) with cost <b>C<sub>2</sub></b> and length <b>L<sub>2</sub></b> creates a new deal with cost <b>C<sub>1</sub></b> + <b>C<sub>2</sub></b> + <b>W</b> and length <b>L<sub>1</sub></b> + <b>L<sub>2</sub></b> (as long as <b>L<sub>1</sub></b> + <b>L<sub>2</sub></b> < |<n>S</b>|), which can in turn be used to create even bigger deals. For example, if W = 0, then a basic deal with cost and length equal to 1 could be combined with itself repeatedly to yield a new deal with both cost and length equal to any positive integer up to (but not including) |<b>S</b>|. |
|
</p> |
|
|
|
<p> |
|
Once Kit purchases a sequence of letters using one (potentially non-basic) deal, it will be matched against |
|
the secret word -- twice! The host will spin the First Fortunate Wheel to select the starting index in <b>S</b> for the |
|
first matching, which is chosen at uniform random such that the sequence will fit entirely within <b>S</b>. Then, |
|
the host will spin the Second Fortunate Wheel to select the starting index for the second matching, which is |
|
chosen at uniform random such that the sequence will fit entirely within <b>S</b> and such that the value given by |
|
the First Fortunate Wheel will not be repeated. For example, if the purchased sequence consists of a single letter, the |
|
First Fortunate Wheel might yield any of the indices in <b>S</b> with probability (1 / |<b>S</b>|) each, and then the Second |
|
Fortunate Wheel might yield any of the remaining indices with probability (1 / (|<b>S</b>|-1)) each. On the other hand, |
|
if the sequence has length |<b>S</b>| − 1, then the First Wheel can yield either 0 or 1, and the Second Wheel must yield the other. If, for both generated indices, the sequence miraculously happens to be equal to the substring of <b>S</b> of the same length starting at that index, then Kit will earn back <b>Y</b>(|<b>S</b>| - |<b>X</b> − <b>ℓ</b>|)<sup>2</sup> + <b>Z</b> points, where <b>ℓ</b> is the length of the sequence. If even one letter is off in either matching, however, Kit will earn no points at all! |
|
</p> |
|
|
|
<p> |
|
Kit is carefully considering his first turn of the game. He obviously wants to maximize the number of points he’ll gain, but worries that choosing the very best move might be suspicious. As such, he’d like to find the expected point values of the <b>M</b> best distinct moves before making his decision. Two moves are distinct iff they involve purchasing different sequences of letters - the deals used are ignored. Note that moves can have negative expected point values, due to the costs of deals. |
|
</p> |
|
|
|
<h3>Input</h3> |
|
<p> |
|
Input begins with an integer <T>, the number of test cases. Each test case begins with a line containing six integers, <b>N</b>, <b>M</b>, <b>W</b>, <b>X</b>, <b>Y</b>, <b>Z</b>. The next line contains the string <b>S</b>. The next <b>N</b> lines each contain two integers, <b>A<sub>i</sub></b> and <b>B<sub>i</sub></b>. |
|
</p> |
|
|
|
<h3>Output</h3> |
|
<p> |
|
For each test case <i>i</i>, output "Case #i: " followed by a space-separated list of real numbers, the <b>M</b> largest expected point values which can be earned, in order. Round these values off to 3 decimal places. |
|
</p> |
|
|
|
<h3>Constraints</h3> |
|
<p> |
|
1 ≤ <b>T</b> ≤ 20 <br/> |
|
2 ≤ |<b>S</b>| ≤ 10<sup>5</sup> <br/> |
|
1 ≤ <b>N</b> ≤ 20 <br/> |
|
1 ≤ <b>A<sub>i</sub></b> ≤ 10<sup>4</sup> <br/> |
|
1 ≤ <b>B<sub>i</sub></b> < |<b>S</b>| <br/> |
|
0 ≤ <b>W</b> ≤ 10<sup>4</sup> <br/> |
|
1 ≤ <b>X</b> < |<b>S</b>| <br/> |
|
0 ≤ <b>Y</b> ≤ 100 <br/> |
|
0 ≤ <b>Z</b> ≤ 100 <br/> |
|
1 ≤ <b>M</b> ≤ 20 <br/> |
|
</p> |
|
|
|
<h3>Explanation of Sample</h3> |
|
<p> |
|
In the first test case, Kit’s best move is to use the basic deal, costing 2 points, to purchase the sequence "Z". No matter what pair of indices the two Fortunate Wheels yield, this sequence will match and earn Kit 5(2 - |1 - 1|)<sup>2</sup> + 6 = 26 points. Any other sequence shorter than |<b>S</b>| cannot match at even a single index, so Kit’s second- and third-best moves consist of using the basic deal to purchase any other single-letter sequence, and simply losing the 2 points. |
|
</p> |
|
|
|
<p> |
|
In the second test case, Kit’s best move consists of combining the third basic deal with itself to yield a deal with cost 5 and length 4, and then purchasing the sequence "OXEN". His three next-best moves, which are the only other moves which get him a positive expected point value, involve using the third basic deal to purchase the sequences "OX", "XE", and "EN". |
|
</p> |
|
|