#abc309h. Ex - Simple Path Counting Problem
Ex - Simple Path Counting Problem
Score : points
问题描述
我们有一个 行和 列的网格。我们将左起第 列、上起第 行的单元格记为 。
已知整数序列 和 ,其长度分别为 和 。
对于所有满足 和 的整数对 ,求以下问题答案之和并对 取模。
- 一个棋子最初放置在点 。有多少种路径可以通过重复以下移动 次将棋子移动到点 ?
- 假设棋子当前位于单元格 ,将其移动至 、 或 ,且在整个过程中不能移出网格范围。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
We have a grid with rows and columns. We denote by the cell in the -th row from the top and -th column from the left.
You are given integer sequences and of lengths and , respectively.
Find the sum, modulo , of the answers to the following question over all integer pairs such that and .
- A piece is initially placed at . How many paths are there to take it to by repeating the following move times?
- Let be the piece's current cell. Move it to , or , without moving it outside the grid.
Constraints
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
3 4 1 2
1
1 2
Sample Output 1
4
For , the following two paths are possible:
For , the following two paths are possible:
Thus, the answer is .
Sample Input 2
5 8 4 5
3 1 4 1
2 7 1 8 2
Sample Output 2
137
Sample Input 3
883671387 87719 10 12
86879 64174 47274 41688 17713 50897 53989 7210 30894 5714
60358 28835 48036 48450 67149 36558 35929 69025 77539 19195 60762 60721
Sample Output 3
941873621
update @ 2024/3/10 08:47:15