Card games - MarisaOJ: Marisa Online Judge

Card games

Time limit: 1000 ms
Memory limit: 256 MB
In a card game consisting of $r$ rounds, you have $n$ cards. Each card has a score $a_i$, and the probability of successfully using card $i$ is $p_i$. In each round: - Start from the first card ($1, 2, ..., n$). - If the card is already used, move to the next card. - If the card is unused: - With probability $p_i$, the card is successfully used, and the round ends. - With probability $1-p_i$, the card fails to be used, so move to the next card. - If all cards are exhausted without success, proceed to the next round. You are tasked to calculate the expected value of the total score obtained after $r$ rounds. ### Input - The first line contains an integer $T$, the number of test cases. - For the next $T$ datasets: - The first line contains two integers $n, r$. - The next $n$ lines each contain two numbers $p_i, a_i$. ### Output - Print a floating-point number representing the expected total score, rounded to at least 6 decimal places. ### Constraints - $1 \le T \le 500$. - $1 \le n \le 222$. - $1 \le r \le 133$. - $0 < p_i < 1$. - $1 \le a_i \le 1000$. ### Sample Test Input: ``` 1 3 2 0.4000 2 0.3000 3 0.8000 1 ``` Output ``` 3.0814240000 ```