Calling Names
Time limit5sMemory limit1024 MB
Count the roll-call orders of N by M seats where no two people sitting directly front and back are called consecutively, modulo 998244353.
- Level
Medium7 of 10
- Topics
- Combinatorics, Math, Dynamic programming
- Solved
- No attempts yet
Problem
Snoopy gets bored in large lectures because roll call takes too long.
One day, bored Snoopy noticed that during roll call, the names of two people who sit adjacent front and back are often called one right after the other, more often than he expected. To check whether this is true, Snoopy decides to calculate it right away.
The lecture hall has seats arranged in a grid of rows and columns, and every seat is occupied. During roll call, each person's name is called exactly once. Among all possible orders in which the names can be called, Snoopy wants to count the orders in which the names of two people who are adjacent front and back are never called consecutively.
Input
The first line contains two positive integers and , separated by a space. ()
Output
On the first line, print the number of orders that satisfy the condition, modulo 998 244 353.