k-Tree
Imagine an infinite tree where every node has exactly k children.
Each edge from a node to its children has weights: 1, 2, 3, ..., k . Starting from the root, you travel along edges.
d denotes the minimum edge weight that MUST be included at least once in your path.
Your task is to Count the number of paths such that: sum of edge weights = n
Return the answer mod 109+7
Example 1:
Input: n = 3 , k = 3 , d = 2
Output: 3
Explanation : All sequences of numbers between 1..3 that sum to 3:
1+1+1 1+2 2+1 3
Now require at least one ≥ 2:
1+2 2+1 3
Valid paths = 3
Example 2:
Input: n = 3 , k = 3 , d = 3
Output: 1
Explanation:
Possible sums:
1+1+1 1+2 2+1 3
Require edge ≥ 3: 3
Answer = 1
Now Your Turn!
Pick the correct output for the given inputInput: n = 4, k = 3, d = 2
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 ≤ n ≤ 100
- 1 ≤ k ≤ 100
- 1 ≤ d ≤ k
- the path contains at least one edge with weight ≥ d.