1258 : Rolling For Days
| 比对Compare | token 相同即通过。中间的空格、制表符、换行可多可少。Matching tokens pass. Extra spaces, tabs, or newlines between them are ignored. |
|---|---|
| 不同则错Differs | token 个数或内容不同即错误。23 与 2 3、02 与 2、2.0 与 2 均视为不同。A different token count or value is wrong. 23 vs 2 3, 02 vs 2, and 2.0 vs 2 all differ. |
| 输入Input | 标准输入,格式见题面。Standard input; format as in the statement. |
| 输出Output | 标准输出。Standard output. |
| 时间与内存Time and memory | 记这一份程序的 CPU 时间和内存峰值。题目上的时间限制、内存限制就是这一份的上限。The record is this program’s CPU time and peak memory. The limits on the problem apply to this one run. |
题目描述Description
In the game TFT, players need to buy units in the store to build up a powerful lineup against other players. Only one-star units will be refreshed in the store, three identical one-star units can be synthesized into a corresponding two-star unit, and three identical two-star units can be synthesized into a corresponding three-star unit. Higher star units will obviously be much more powerful than lower star units. The units refreshed in the store are random, and refreshing requires coins. So it’s possible that you can’t get the units you want although having a lot of coins.
As a disciplined player, you’re curious about just how many refreshes are needed to complete a particular deck. To that end, you’re going to start by solving the following simplified problem:
There are a total of \(n\) cards in the store’s card pool, which are categorized into \(m\) kinds, where the \(i\)-th kind of card has a total of \(a_i\) cards. You have decided on your target deck, and your target deck requires \(b_i\) cards of the \(i\)-th kind. Each time you refresh, one card will be randomly drawn from the remaining cards in the card pool with equal probability. If the drawn card is not needed (i.e., the number of cards in this kind already purchased is equal to the number that your target deck requires), you’ll put the card right back into the card pool; otherwise, you’ll purchase the card and remove it from the card pool. How many refreshes do you expect to need to complete your target deck? Since the answer may be large and floating point errors cannot be ignored, please output the answer modulo \(998244353\).
Formally, let \(M=998244353\) . It can be shown that the answer can be expressed as an irreducible fraction \(\frac{p}{q}\) , where \(p\) and \(q\) are integers and \(q\not\equiv 0\pmod M\) . Output the integer equal to \(p\cdot q^{-1} \bmod M\) . In other words, output such an integer \(x\) that \(0\le x<M\) and \(x\cdot q\equiv p\pmod M\) .
输入格式Input
The first line contains two integers \(n,m(1\le n\le 1000;1\le m\le 12)\) , denoting the total number of cards and the number of kinds.
The second line contains \(m\) integers \(a_1,a_2,...,a_m(1\le a_i\le n,\sum_{i=1}^ma_i=n)\) , denoting the numbers of cards of each type.
The third line contains \(m\) integers \(b_1,b_2,...,b_m(0\le b_i\le a_i)\) , denoting the numbers of cards required for your target deck.
输出格式Output
Output a single integer, denoting the expect number of refreshes modulo \(998244353\) .
样例Sample
提示Hint
The answer for sample case #1 is \(\frac{49}{12}\).
出题Author
FUDAN