You have a game with levels and teleporters. Each teleporter goes from level to level . You start at level and want to reach level . How many different routes are there from level to level ?
Print the answer modulo . This is the counting version of the previous problem.
Instead of finding the longest path, you count all paths. The approach is the same: topological sort plus DP.
But instead of taking the max, you sum the ways. Before reading on, think: what would the DP state be?
What's the transition?