Блог пользователя cfisfake

Автор cfisfake, история, 6 лет назад, По-английски

How to solve APIO 2016 Boats? I couldn't find a detailed solution anywhere and I tried looking for similar problems to it but couldn't find detailed explanation. The question formally states to find the number of increasing subsequences of length n where each element Ai has constraint Li<=A[i]<=R[i]. the arrays L[i] and R[i] are given to you. n is upto 300.

  • Проголосовать: нравится
  • -7
  • Проголосовать: не нравится

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Div. 1 500 from here is the same. You can see the editorial in the comment.

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

The naive dp is something like this: dp[i][j]= answer for the first i elements given that the last chosen element has value j. The problem here is that j can be too large. However note that we can partition the integers into certain partitions, and only the partition to which j belongs should matter: to be precise, let t1 < t2 < ... < tN be the set {L1, ... , Ln, R1, ... , Rn} in sorted order, then it only matters to which of the intervals (ti, ti - 1) j belongs to. So the dp will now look like this: dp[i][j]= answer for the first i elements given that the last element belongs to the j'th interval. The transitions will be like this: iterate over the k < i for which the number is in another interval, multiply the number of increasing subsequences of length k - i contained in the j'th interval (O(1) formula is easy to derive) by and add it to result. There are a few minor details to work out here (which I unfortuntely I couldn't do in contest time :( ).