logo AlgoBeat OnlineJudge
登录 注册

#217544. [ICPC 2018 Shenyang R] Sequences Generator

内存限制:512 MiB 时间限制:8000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

The RBM Second Generation of Dual Core Microprocessor Chip, also known as RBM2gDCMC, can generate a digital sequence of length . Each digit in a sequence provided by RBM2gDCMC is regarded as an integer between and in this problem.

Now I will show you the passcode for the email belonging to Gini Romety, which is a sequence of length with integers between and . You are asked to calculate the probabilities of the coincidence with Gini Romety's passcode for all consecutive subsequence of length in a sequence generated by RBM2gDCMC.

输入格式

The input contains several test cases, and the first line contains a positive integer indicating the number of test cases which is up to .

For each test case, the first line contains two integers and , satisfying , which are described as above.

The following lines describe the generating logic for all digits in a sequence built by RBM2gDCMC. The -th line of them contains two integers and , satisfying and , and following integers, denoted by , where and . These data indicate that for the -th digit the probability of being an integer in is zero, and the probability of being an integer in is .

The next line contains integers, denoted by , describing the passcode for Gini Romety's email, where .

We guarantee that the sum of in all test cases is no larger than .

输出格式

For each test case, output a line containing "Case #x:" (without quotes) at first, where is the test case number starting from .

After that, output lines such that the -th of them contains a real number indicating the probability of the coincidence for the passcode of Gini Romety's email and the subsequence of a sequence produced by RBM2gDCMC from the -th digit to the -th one with an absolute error of at most . Precisely speaking, assume that your answer is and the jury's answer is , your answer will be considered correct if , where means the absolute value of .

样例

样例输入 1

1
5 3
1 3 100000000 200000000 700000000
1 3 600000000 150000000 250000000
1 3 333333333 333333334 333333333
3 4 450000000 550000000
1 3 999999998 1 1
1 2 3

样例输出 1

Case #1:
0.004999999995000
0.090000000180000
0.000000000000000

数据范围与提示

In the sample case, the probability matrix is

and thus the answers in the output are

  • ,
  • ,

respectively.