#P3239. [HNOI2015] 亚瑟王

    ID: 2288 远端评测题 1000~2000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划,dp2015湖南Special Judge期望

[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 nn cards. During the game, the player arranges the nn cards in some order, and after arranging, numbers the cards from front to back as 1n1 - n. In this problem, the order is already fixed, which is the input order. Each card has a skill. The activation probability of the ii-th card’s skill is pip_i, and if it successfully activates, it deals did_i 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, pip_i is neither 00 nor 11, i.e., 0<pi<10 < p_i < 1. A game consists of rr 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:

  1. 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.

  1. Otherwise (this card has not activated its skill in this game), let this card be the ii-th card.

2.1. Attempt to activate its skill with probability pip_i.

2.2. If the skill activates, deal did_i damage to the opponent and end this round.

2.3. If this card is already the last one (i.e., ii equals nn), 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 TT, representing the number of testdata groups.

Then there are TT groups of data.

The first line of each group contains two space-separated integers nn and rr, representing the number of cards and the number of rounds in the game, respectively.

Then follow nn lines, each containing a real number and an integer separated by a space, describing one card. The two numbers on the ii-th line are pip_i and did_i, representing the activation probability (real number) of the ii-th card’s skill and the damage (integer) dealt when the skill activates. It is guaranteed that pip_i has at most 44 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 10810^{-8}—i.e., aoa108\frac{|a-o|}{a} \leq 10^{-8} (where aa is the standard answer and oo is your output). It is recommended to output 1010 decimal places.

1
3 2
0.5000 2
0.3000 3
0.9000 1
3.2660250000

Hint

There are 1313 possible cases:

  1. In round 11, card 11 activates; in round 22, card 22 activates.

Probability is 0.150.15, damage is 55.

  1. In round 11, card 11 activates; in round 22, card 33 activates.

Probability is 0.3150.315, damage is 33.

  1. In round 11, card 11 activates; in round 22 no skill activates.

Probability is 0.0350.035, damage is 22.

  1. In round 11, card 22 activates; in round 22, card 11 activates.

Probability is 0.0750.075, damage is 55.

  1. In round 11, card 22 activates; in round 22, card 33 activates.

Probability is 0.06750.0675, damage is 44.

  1. In round 11, card 22 activates; in round 22 no skill activates.

Probability is 0.00750.0075, damage is 33.

  1. In round 11, card 33 activates; in round 22, card 11 activates.

Probability is 0.15750.1575, damage is 33.

  1. In round 11, card 33 activates; in round 22, card 22 activates.

Probability is 0.047250.04725, damage is 44.

  1. In round 11, card 33 activates; in round 22 no skill activates.

Probability is 0.110250.11025, damage is 11.

  1. In round 11 no skill activates; in round 22, card 11 activates.

Probability is 0.01750.0175, damage is 22.

  1. In round 11 no skill activates; in round 22, card 22 activates.

Probability is 0.005250.00525, damage is 33.

  1. In round 11 no skill activates; in round 22, card 33 activates.

Probability is 0.0110250.011025, damage is 11.

  1. In round 11 no skill activates; in round 22 no skill activates.

Probability is 0.0012250.001225, damage is 00.

The expected damage is the sum of the products of probabilities and corresponding damages, which is 3.2660253.266025.

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 pip_i and did_i 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