#abc232e. E - Rook Path
E - Rook Path
Score : points
问题陈述
存在一个 的棋盘格,包含 行(从上至下编号)和 列(从左至右编号)。令 表示第 行从上数起、第 列从左数起的方格。
棋盘上有一个初始位于 的车(rook)。Takahashi 将执行以下操作 次:
- 将车移动到与当前占据方格在同一行或同一列的其他方格上。注意,必须移动到与当前方格不同的位置。
在经过 次操作后,有多少种方法可以使车最终位于 ?由于答案可能非常大,请计算结果对 取模后的值。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There is a -square grid with horizontal rows and vertical columns. Let denote the square at the -th row from the top and -th column from the left.
The grid has a rook, initially on . Takahashi will do the following operation times.
- Move the rook to a square that shares the row or column with the square currently occupied by the rook. Here, it must move to a square different from the current one.
How many ways are there to do the operations so that the rook will be on in the end? Since the answer can be enormous, find it modulo .
Constraints
Input
Input is given from Standard Input in the following format:
Output
Print the number of ways to do the operations so that the rook will be on in the end, modulo .
Sample Input 1
2 2 2
1 2 2 1
Sample Output 1
2
We have the following two ways.
- First, move the rook from to . Second, move it from to .
- First, move the rook from to . Second, move it from to .
Sample Input 2
1000000000 1000000000 1000000
1000000000 1000000000 1000000000 1000000000
Sample Output 2
24922282
Be sure to find the count modulo .
Sample Input 3
3 3 3
1 3 3 3
Sample Output 3
9
update @ 2024/3/10 10:07:09