PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#QHD0000033. Cây K (k-Tree)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Cây K (k-Tree)
k-Tree
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Consider an infinite rooted tree. From every vertex, exactly edges lead to its children, with edge weights .
A path starts at the root and follows edges downward. Its weight is the sum of its edge weights. Count paths whose total weight is exactly and which contain at least one edge of weight at least .
Print the result modulo .
Input
One line contains the integers , , and .
Output
Print the number of valid paths modulo .
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; ; .
Examples
Input
3 3 2
Output
3
Explanation
The paths with total weight and at least one edge of weight at least have sequences , , and . The sequence does not qualify. Thus the answer is .