#P8580. [CoE R5] 罚球

    ID: 8867 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP数学洛谷原创O2优化期望高斯消元洛谷月赛

[CoE R5] 罚球

Problem Description

There are nn people playing a free throw game. The rules are as follows:

  • Each person is numbered 1,2,,n1,2,\dots,n. At the beginning, player 11 takes a free throw. After that, the next player who has not been eliminated takes a free throw. In particular, after player nn comes player 11.
  • If the shooter does not hit the backboard, they are eliminated immediately.
  • If the shooter hits the backboard but does not score, then if the previous player scored, this shooter will be eliminated; otherwise, they will not be eliminated.
  • The game ends when there is only one person left.

Note that the first player will not be eliminated if they hit the backboard but do not score.

Among these nn people, for player ii, the probability of not hitting the backboard is ai1000\dfrac{a_i}{1000}, and the probability of hitting the backboard but not scoring is bi1000\dfrac{b_i}{1000}. Find the expected total number of free throws taken by all players when the game ends.

Input Format

The first line contains two integers n,tn,t, representing the number of players and the subtask index.
The next nn lines each contain two integers ai,bia_i,b_i, and it is guaranteed that 0ai+bi10000\le a_i+b_i\le1000.

Output Format

Output one line: the expected total number of free throws taken by all players. If the game will never end, output 1-1. Otherwise, output the value modulo 106+3310^6+33.

2 8
200 400
200 400
888921
7 8
321 637
321 637
321 637
321 637
321 637
321 637
321 637
818968
6 10
338 270
229 413
132 133
141 173
157 686
616 250
315860
8 10
338 270
229 413
132 133
141 173
157 686
616 250
0 0
0 0
-1

Hint

About modulo

If you do not know how to take modulo of rational numbers, see here.


Sample Explanation

Input #1\#1:

For everyone, the probability of not hitting the backboard is 15\dfrac{1}{5}, and the probability of hitting the backboard but not scoring is 25\dfrac{2}{5}. The expected number of free throws is 259\dfrac{25}{9}.

The calculation is as follows (black means eliminated, red means no score but not eliminated, blue means scored):

$$\dfrac{1}{5}+\red{\dfrac{2}{5}}\times(\dfrac{1}{5}+\red{\dfrac{2}{5}}\times(...)+\blue{\dfrac{2}{5}}\times(...))+\blue{\dfrac{2}{5}}\times(\dfrac{3}{5}+\blue{\dfrac{2}{5}}\times(...))=\dfrac{25}{9}$$

Input #2\#2:

For everyone, the probability of not hitting the backboard is 3211000\dfrac{321}{1000}, and the probability of hitting the backboard but not scoring is 6371000\dfrac{637}{1000}. The expected number of free throws is 100000057959\dfrac{1000000}{57959}.


Constraints

This problem uses bundled tests.

Test point properties: | t=t= | Property | Score | | :----------: | :----------: | :----------: | | 11 | n=1n=1 | 22 | | 22 | ai=bi=0a_i=b_i=0 | 22 | | 33 | ai=1000a_i=1000 | 44 | | 44 | bi=1000b_i=1000 | 44 | | 55 | ai=0,b1=0,i>1,bi=1000a_i=0,b_1=0,\forall i>1,b_i=1000 | 66 | | 66 | ai=bi=500a_i=b_i=500 | 66 | | 77 | ai=0,bi=500a_i=0,b_i=500 | 66 | | 88 | ai,bia_i,b_i are both fixed values, and the answer is not 1-1 | 1919 | | 99 | 1n111 \le n \le 11 | 2626 | | 1010 | 1n151 \le n \le 15 | 88 | | 1111 | No special property | 1717 |

For 100%100\% of the testdata, 1n181 \le n \le 18, 0ai,bi,ai+bi10000 \le a_i,b_i,a_i+b_i \le 1000.

Subtask 1010 of this problem is scored in two parts, corresponding to t{10,11}t \in \{10,11\}.

It is guaranteed that there is no case where the denominator is a multiple of 106+3310^6+33.

Translated by ChatGPT 5