The state is ways[v], the number of ways to reach level from level . The base case is ways[1] = 1 (one way to be at the start). The transition is: for each edge , add ways[u] to ways[v]. This says "every way to reach extends to a way to reach ". Why does this work?
Because the graph is a DAG, there are no cycles. Each path is counted exactly once. When you process in topological order, you've already counted all ways to reach its predecessors , so you can sum them safely.