The Day of Going to the Training Camp
Time limit1sMemory limit1024 MB
Count sequences of length N over values 1..M that avoid any local peak (a[i-1] < a[i] > a[i+1]), modulo 998244353.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Combinatorics, Math, Implementation
- Solved
- No attempts yet
Problem
On the day of going to the training camp, Ukje suddenly wondered. Why is the training camp in Nonsan? Why why?
The reason is…
Nonsan (non-san) is not a mountain (san). A sequence of length 3 is a mountain if . A sequence is a nonsan if no three adjacent terms form a mountain. In other words, for a sequence of length , there is no index with and .
Let us find out how many nonsan sequences there are.
Input
The first line gives and .
Output
Among all sequences of length made of integers from to , print the number of nonsan sequences modulo .