PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000266. Bước nhảy của Tak (Leaping Tak)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Bước nhảy của Tak (Leaping Tak)
Leaping Tak
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
There are cells numbered 1 through . Tak starts at cell 1. Given pairwise disjoint inclusive integer intervals , each move chooses an integer in their union and advances from to without passing . Count the sequences of moves reaching , modulo .
Input
First line: . Next lines: .
Output
Print the number of ways modulo .
Subtasks
- Subtask 1 (20 points): ; ; ; pairwise disjoint intervals.
- Subtask 2 (30 points): ; ; ; pairwise disjoint intervals; .
- Subtask 3 (50 points): ; ; ; pairwise disjoint intervals.
Example 1
Input
5 2
1 1
3 4
Output
4
Explanation
The move sequences are (1,1,1,1), (1,3), (3,1), (4).
Example 2
Input
5 2
3 3
5 5
Output
0
Explanation
Neither 3 nor 5 can form a total of 4.
Example 3
Input
5 1
1 2
Output
5
Explanation
The five compositions of 4 use parts 1 and 2.
Example 4
Input
60 3
5 8
1 3
10 15
Output
221823067
Explanation
Count move sequences totaling 59 and reduce modulo 998244353.