#P3239. [HNOI2015] 亚瑟王
[HNOI2015] 亚瑟王
Description
Xiao K was accidentally brainwashed by the LL cult, to the extent that he even wants to quit the King Arthur cult. He decides to play one last game of King Arthur before quitting. Since it is the final battle, it must look good. As is well known, King Arthur is a game of luck, and the activation of skills is probabilistic.
As an unlucky player (slang “African”), and also a former OIer, Xiao K naturally wants to maximize the expected damage dealt. But he has not coded for many years and cannot even code Splay correctly, so he hopes you can help him experience what it is like to be “European” (i.e., lucky).
In this problem we consider a simplified model of the game. The player has a deck of cards. During the game, the player arranges the cards in some order, and after arranging, numbers the cards from front to back as . In this problem, the order is already fixed, which is the input order. Each card has a skill. The activation probability of the -th card’s skill is , and if it successfully activates, it deals damage to the opponent. Only by activating the skill can a card deal damage to the opponent. Considering practical factors and Xiao K’s “African” luck, is neither nor , i.e., . A game consists of rounds. In each round, the system starts from the first card and considers each card in order. In one round, for each card considered in order:
- If this card has already activated its skill in this game, then
1.1. If this card is not the last one, skip it (consider the next card); otherwise (it is the last one), end this round.
- Otherwise (this card has not activated its skill in this game), let this card be the -th card.
2.1. Attempt to activate its skill with probability .
2.2. If the skill activates, deal damage to the opponent and end this round.
2.3. If this card is already the last one (i.e., equals ), end this round; otherwise, consider the next card.
Please help Xiao K compute the expected damage this deck can deal in one game.
Input Format
The first line of the input file contains an integer , representing the number of testdata groups.
Then there are groups of data.
The first line of each group contains two space-separated integers and , representing the number of cards and the number of rounds in the game, respectively.
Then follow lines, each containing a real number and an integer separated by a space, describing one card. The two numbers on the -th line are and , representing the activation probability (real number) of the -th card’s skill and the damage (integer) dealt when the skill activates. It is guaranteed that has at most decimal places and is a valid probability.
Output Format
For each group of data, output one line containing a real number, which is the expected damage dealt by this deck in one game. For each output line, your output will be judged correct only if its relative error with the standard answer does not exceed —i.e., (where is the standard answer and is your output). It is recommended to output decimal places.
1
3 2
0.5000 2
0.3000 3
0.9000 1
3.2660250000
Hint
There are possible cases:
- In round , card activates; in round , card activates.
Probability is , damage is .
- In round , card activates; in round , card activates.
Probability is , damage is .
- In round , card activates; in round no skill activates.
Probability is , damage is .
- In round , card activates; in round , card activates.
Probability is , damage is .
- In round , card activates; in round , card activates.
Probability is , damage is .
- In round , card activates; in round no skill activates.
Probability is , damage is .
- In round , card activates; in round , card activates.
Probability is , damage is .
- In round , card activates; in round , card activates.
Probability is , damage is .
- In round , card activates; in round no skill activates.
Probability is , damage is .
- In round no skill activates; in round , card activates.
Probability is , damage is .
- In round no skill activates; in round , card activates.
Probability is , damage is .
- In round no skill activates; in round , card activates.
Probability is , damage is .
- In round no skill activates; in round no skill activates.
Probability is , damage is .
The expected damage is the sum of the products of probabilities and corresponding damages, which is .
Constraints: For all testdata, $1 \leq T \leq 444, 1 \leq n \leq 220, 0 \leq r \leq 132, 0 < p_i < 1, 0 \leq d_i \leq 1000$.
Unless otherwise specified in the remarks, the and in the testdata are randomly generated.
Please be aware of possible floating-point precision issues and take appropriate measures.
This problem uses special_judge.
Translated by ChatGPT 5
京公网安备 11011102002149号