Bonus: Brief idea of solution using Matrix Exponentiation. Counting Numbers (2220) Link to Task This problem is a very standard application of Digit DP. Digit DP can be used to solve problems where we need to c
✔ Counting Numbers Digit Dp Code Graph Algorithms StatusNameTagsLink ✔ Counting Rooms BFS Code ✔ Labyrinth BFS Code ✔ Building Roads BFS DFS Forest Counting Code ✔ Message Route BFS Code ✔ Building Teams Bicoloring DFS Code ✔ Round Trip Cycle in undirected graph DFS Code ✔...
Code Counting Numbers (2220) It is a good problem for learning digit DP. dp state is defined as follows: dp[ith digit from left][previous digit][leading zeroes][tight] leading zeroes are the zeroes that come before the first non-zero digit in a number eg:0034, 012....
dp[i][x] = number of ways to make sum x using subsets of the numbers 1..i . We say there is one way (the empty set) to make sum 0, so dp[0][0] = 1; For counting number of ways to make sum x using values up to i, we consider the number i. Either we didn't include...