## E - Random LIS Editorial by evima

First, when we consider the length of the LIS, it is only the state after “compression” of the elements that matters. The number of ways to divide \(N\) objects into some number of groups and ordering them is called the Ordered Bell number or Fubini number, and there are \(4683\) such ways for \(N = 6\).

For a fixed such way, after taking the minimum within a group, we need to solve the following problem:

- Find the number of strictly increasing sequences of length \(k\) such that \(1 \leq a_i \leq M_i (1 \leq i \leq k)\).

Let us compress \(M_i\) and let dp[\(i\)][\(j\)]:= (the number of combinations of first \(i\) elements such that the last belongs to the \(j\)-th segment). We can compute it correctly by only considering the transitions that choose the \(i+1, \cdots, k\) elements from the same segment that is Segment \(j+1\) or above. The time complexity of this part will be \(\mathrm{O}(N^3)\). (The coefficient has the form \(\binom{x}{y}\) where \(x\) is large, but \(y\) is at most \(N\), so we can compute it fast.)

posted:

last update: