Pattern : 8 question Platform : Codechef u can say div-2 contest
At Motorq, real-time vehicle telemetry is forwarded through a multi-tier mesh of N gateway nodes, numbered from 1 to N.
Due to hardware topology rules, data can only flow forward: gateway i can transmit data packets directly to the next n_i consecutive gateways (i.e., gateways i + 1, i + 2, ..., i + n_i).
A valid routing path from a source gateway A to a destination hub B (A < B) is a sequence of gateways g_1, g_2, ..., g_k such that:
Two routing paths are considered distinct if they differ in at least one intermediate gateway node.
Given a primary destination hub B and Q query source gateways, determine the total number of distinct routing paths from each source gateway A to destination hub B.
Since the number of paths can be very large, compute the result modulo 10^9 + 7.
Input
5 5
3
2
2
1
0
3
1
2
3
Output
6
3
2
Explanation
Gateway Transmission Connections:
Gateway 1 (n_1 = 3): connects to {2, 3, 4}
Gateway 2 (n_2 = 2): connects to {3, 4}
Gateway 3 (n_3 = 2): connects to {4, 5}
Gateway 4 (n_4 = 1): connects to {5}
Gateway 5 (n_5 = 0): terminal node
Query 1 (A = 1 -> B = 5): The 6 distinct routing paths are:
MotorQ • Pending