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

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

can anyone suggest approach to solve this problem?
https://codeforces.me/gym/102157/problem/3

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

»
5 лет назад, # |
Rev. 3   Проголосовать: нравится +3 Проголосовать: не нравится

I think for this problem you're DP state is going to be DP[current index on first row][what elements are matched on bottom row]

We can use a bitmask to represent what elements are matched on the bottom row (with respect to our current index on the first row). Because e <= 4, the we only need to consider "windows" of length 9, so our bit mask goes to 2^9 which is 512. Transitions then become trivial.

I believe the overall complexity is O(N * 2^(2E+1) + N*K).