Official

G - Count Strictly Increasing Sequences Editorial by en_translator


Let dpi,j,k\mathrm{dp}_{i,j,k} be “the number of ways to determine the (k+1)(k+1)-th and later digits of Si,Si+1,,Sj1S_i,S_{i+1},\ldots,S_{j-1} such that Si<Si+1<<Sj1S_i \lt S_{i+1} \lt \ldots \lt S_{j-1} within those digits.” (DP stands for Dynamic Programming.) Here, within the specified segment, the (k+1)(k+1)-th digits are weakly increasing; additionally, within a segment with the same (k+1)(k+1)-th digits, the (k+2)(k+2)-th and later digits must form weakly increasing integers. Thus, the DP can be evaluated by considering the ways to split Si,Si+1,,Sj1S_i,S_{i+1},\ldots,S_{j-1} into segments where the (k+1)(k+1)-th segments are 0, 1, \ldots, and 9. Specifically, we evaluate dpi,j,k,l=\mathrm{dp}_{i,j,k,l} = “the number of ways to determine the (k+1)(k+1)-th and later digits of Si<Si+1<<Sj1S_i \lt S_{i+1} \lt \ldots \lt S_{j-1} such that Si<Si+1<<Sj1S_i \lt S_{i+1} \lt \ldots \lt S_{j-1} within those digits and zero or more first (k+1)(k+1)-th digits are ll,” which can be evaluated in a total of O(N3Mb)\mathrm{O}(N^3Mb) time (where bb is the number of kinds of digits).

posted:
last update:



2025-03-14 (Fri)
13:11:18 +00:00