8682: Two Frogs

内存限制:128 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述


In the Lonely Mountain, there are a lot of treasure well protected by dwarfs. Later, one day, the last dragon Smaug came and sensed the treasure being. As known to all, dragons are always much too greedy for treasure. So definitely, the war between dwarfs and Smaug begins.

During the war, two goblins Alice and Bob are turned into frogs by Gandalf, The Grey. In front of them, there are nnn lotus leaves in a line. In order to break the spell, they must jump from the 111-st lotus leaf to the nnn-th lotus leaf. If the frog is now on the iii-th lotus leaf instead of the nnn-th lotus leaf, it can jump to a lotus leaf in range (i,i+ai](i, i + a_i](i,i+ai].

Goblins are lack of intelligence and it's also true even after turned into frogs. So Alice and Bob will jump randomly, which means, they will separately pick an available lotus leaf in every jump uniformly at random.

Since Alice and Bob have already being playing games for decades, so they want to know the probability that they jump to the nnn-th lotus leaf with the same count of jumps.

输入格式


The first line contains an integer nnn (2≤n≤8000)(2 \leq n \leq 8\,000)(2n8000), denoting the number of lotus leaf.
The second line contains n−1n-1n1 integers a1,a2,…,an−1a_1, a_2, \ldots, a_{n-1}a1,a2,,an1, where the iii-th integer aia_iai (1≤ai≤n−i)(1 \leq a_i \leq n-i)(1aini) indicates the range of lotus leaves that can be reached from the iii-th lotus leaf.

输出格式


Output a line containing a single integer, indicating the probability that Alive and Bob jump to nnn-th lotus leaf with the same count of jumps, taken modulo 998244353998\,244\,353998244353.
Formally speaking, let the result, which is a rational number, be xy\frac{x}{y}yx as an irreducible fraction, you need to output x⋅y−1mod998244353x \cdot y^{-1} \bmod{998\,244\,353}xy1mod998244353, where y−1y^{-1}y1 is a number such that y⋅y−1≡1(mod998244353)y \cdot y^{-1} \equiv 1 \pmod{998\,244\,353}yy11(mod998244353). You may safely assume that such y−1y^{-1}y1 always exists.

输入样例 复制

5
1 1 1 1

输出样例 复制

1

分类标签