Lest I Forget

Index
Home

❯

Code

❯

Algos

❯

Patterns

❯

Dynamic Programming

❯

Digit DP

Digit DP

Jul 22, 20261 min read

Digit DP

Typical state: position, tight bound, leading-zero state, and the problem-specific state.

See Counting Numbers for a complete template and implementation.

Balanced Digit Sums

https://leetcode.com/problems/number-of-balanced-integers-in-a-range/description/

The only optim is to use the offset trick and reduce state to even - odd

  • Impl trick, use offset like this, you only need to translate on array access
int& mem = dp[pos][ti][lz][sum+off];
if(mem != -1) return mem;

See you in another file