Graph Theory37 sections · 1633 units
Open in Course

Why you Add Counts

Paths are independent

When you compute dp[v] from dp[u], you are saying: every path that reaches uu can be extended by one edge to reach vv. So the number of new paths to vv through uu is exactly dp[u]. Since paths through different predecessors are distinct, you add them all: dp[v] = Σ dp[u] for all edges (u,v)(u, v).

This is different from shortest or longest path, where you take min\min or max\max. Counting problems use addition.