8609: Wheel of Fortune

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

题目描述

In the famous card-collecting game Hearthstone, there is an exciting card named Yogg Saron, Master of Fate, with a battlecry effect of "If you've cast 10 spells during the game, spin the Wheel of Yogg Saron!" 

Six distinct options are contained in the Wheel of Yogg Saron, with a probability of being chosen for each option. Among all options, the one with the least probability of being chosen is "Rod of Roasting." However, this option also has the most devastating effect: Randomly cast "Pyroblast" until a player dies! Here, "Pyroblast" is a spell of mage class, with the effect of dealing 10 damage to some unit.

Now, given the health point of you and your opponent and the health point of minions on the board, you want to know: If now a battlecry of Yogg Saron, Master of Fate is triggered and the option of "Rod of Roasting" is chosen, what is the probability of you surviving the pyroblasts and winning the game?

Formally, assume your health point is A(A>0), and the health point of at most7 minions on your board are a1,a2,…,a7(ai≥0,ai=0 iff this minion doesn’t exist), respectively. Also, your opponent's health point is B(B>0) and the health point of at most 7 minions on your opponent's board are b1,b2,…,b7(bi≥0,bi=0 iff this minion doesn’t exist), respectively. The option of "Rod of Roasting" is equivalent to the following stochastic process:
  • Repeat until A≤0 or B≤0: Choose from A,B,a1,a2,…,a7,b1,b2,…,b7 an element x greater than zero uniformly at random and set x←x−10
  • If B≤0, you win. Otherwise, your opponent wins.

输入格式

The first line contains eight integers A,a1,a2,…,a7(0<A≤107,0≤ai≤107), denoting the health point of you and your minions.
The second line contains eight integers B,b1,b2,…,b7(0<B≤107,0≤bi≤107)B, denoting the health point of your opponent and your opponent's minions.

输出格式

Output an integer in a line, denoting the probability of you winning the game. Under the input constraints of this problem, it can be shown that the answer can be written as P\Q, where P and Q are coprime integers and Q≢0(mod998244353). You need to output P⋅Q−1(mod998244353) as an answer, where Q−1 is the modular inverse of Q with respect to 998244353.

输入样例 复制

30 5 0 0 0 0 0 0
30 5 0 0 0 0 0 0

输出样例 复制

499122177