8498: Equipment Upgrade

内存限制:128 MB 时间限制:10 S
题面:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

Little Q is playing an RPG game. In this game, the weapon can be upgraded. Initially, the weapon is at level 00, and the upper bound of the level is n. Assume the current level is ii (0i<n), Little Q can pay ci coins to upgrade the weapon, the next level will be i+1iwith probability pi, and will be i-j(1ji) with probability k=1iwkwj.

Though Little Q is very rich, he is still wondering the expected number of coins for him to upgrade the weapon from level 00 to level n. Please write a program to help him.

输入格式

The first line contains a single integer T(1T300), the number of test cases. For each test case:

The first line contains a single integer n (2n100,000), denoting the upper bound of the level.

The ith (1in) of the following n lines contains two integersPi1 andci1 (1Pi1,ci1100), describing the success probability and the cost for level i-1i1. Here pi1=100Pi1. It is guaranteed thatP0=100.

The next line contains n-1 integers w1,w2,,wn1 (1wi100).

It is guaranteed that the sum of all n is at most 500,000.

输出格式

For each test case, output a single line containing an integer, denoting the expected number of coins to level n

More precisely, if the answer is P/Q, you should output the minimum non-negative integer rsuch that qrp(mod998,244,353). You may safely assume that such r always exists in all test cases.

输入样例 复制

2
2
100 1
50 5
1
3
100 1
70 2
50 3
2 3

输出样例 复制

12
228170152